From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; rv:1.7.3) Gecko/20041020 Firefox/0.10.1 Description of problem: *** Notes: CADENCE_RD 21-OCT-2004 13:26:25 Incorrect results returned by ftell() The problem can be reproduced with the following two C programs. main1.c ------- #include <stdio.h> main() { int a = 0, b = 0; int c, code, position; FILE *fd; fd = fopen("input.dat","r"); a = fgetc(fd); b = fgetc(fd); code = fgetc(fd); c = 'c'; code = ungetc(c, fd); position = ftell(fd); printf("c - ungetc. position = %d\n", position); a = fgetc(fd); position = ftell(fd); printf("c - getc. position = %d\n", position); fclose(fd); } main2.c ------- #include <stdio.h> main() { int a = 0, b = 0, ci; int c, code, position; FILE *fd; fd = fopen("input.dat","r"); a = fgetc(fd); b = fgetc(fd); code = fgetc(fd); c = 'c'; code = ungetc(c, fd); a = fgetc(fd); position = ftell(fd); printf("c - ungetc. position = %d\n", position); fscanf(fd, "%x %x %x", &a, &b, &ci); printf("a, b, ci = %x, %x, %x\n", a, b, ci); fscanf(fd, "%x %x %x", &a, &b, &ci); printf("a, b, ci = %x, %x, %x\n", a, b, ci); fseek(fd, position, 0); fscanf(fd, "%x %x %x", &a, &b, &ci); printf("a, b, ci = %x, %x, %x\n", a, b, ci); fflush(fd); rewind(fd); a = fgetc(fd); printf("a, b, ci = %x, %x, %x\n", a, b, ci); fclose(fd); } input.dat: ---------- aab 11111111 00000000 1 11111111 11111111 0 00000000 11111111 0 Note: In main1.c, if we add an ftell() call right after the fopen(), the problem won't show. However, doing the same thing to main2.c won't avoid the problem. Version-Release number of selected component (if applicable): glibc-headers-2.3.2-95.28 How reproducible: Always Steps to Reproduce: 1.run above test cases 2. 3. Actual Results: ftell() returns incorrect info Expected Results: ftell() returns correct info Additional info:
Created attachment 106069 [details] reproducer
Created attachment 106070 [details] modified reproducer
http://sources.redhat.com/ml/libc-hacker/2004-11/msg00003.html
Should be fixed in glibc-2.3.3-76 in rawhide, RHEL4 and RHEL3 rpms will come later.
Fix added to glibc-2.3.2-95.31, for the time being available from ftp://people.redhat.com/jakub/glibc/2.3.2-95.31/