Bug 137885 - [RHEL3] ftell() not working correctly
[RHEL3] ftell() not working correctly
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc (Show other bugs)
3.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-11-02 11:10 EST by Dave Maley
Modified: 2007-11-30 17:07 EST (History)
2 users (show)

See Also:
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:


Attachments (Terms of Use)
reproducer (831 bytes, text/x-csrc)
2004-11-02 11:15 EST, Dave Maley
no flags Details
modified reproducer (2.27 KB, text/x-csrc)
2004-11-02 11:15 EST, Dave Maley
no flags Details

  None (edit)
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/

Note You need to log in before you can comment on or make changes to this bug.