Bug 137885

Summary: [RHEL3] ftell() not working correctly
Product: Red Hat Enterprise Linux 3 Reporter: Dave Maley <dmaley>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0CC: drepper.fsp, tao
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 2.3.2-95.33 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-06-30 15:22:41 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Attachments:
Description Flags
reproducer
none
modified reproducer none

Description Dave Maley 2004-11-02 11:10:42 EST
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:
Comment 2 Dave Maley 2004-11-02 11:15:09 EST
Created attachment 106069 [details]
reproducer
Comment 3 Dave Maley 2004-11-02 11:15:46 EST
Created attachment 106070 [details]
modified reproducer
Comment 5 Jakub Jelinek 2004-11-10 08:25:05 EST
Should be fixed in glibc-2.3.3-76 in rawhide, RHEL4 and RHEL3 rpms will come later.
Comment 9 Jakub Jelinek 2004-12-23 16:20:51 EST
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/