Bug 137885 - [RHEL3] ftell() not working correctly
Summary: [RHEL3] ftell() not working correctly
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc
Version: 3.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-11-02 16:10 UTC by Dave Maley
Modified: 2007-11-30 22:07 UTC (History)
2 users (show)

Fixed In Version: 2.3.2-95.33
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-06-30 19:22:41 UTC
Target Upstream Version:
Embargoed:


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

Description Dave Maley 2004-11-02 16:10:42 UTC
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 16:15:09 UTC
Created attachment 106069 [details]
reproducer

Comment 3 Dave Maley 2004-11-02 16:15:46 UTC
Created attachment 106070 [details]
modified reproducer

Comment 5 Jakub Jelinek 2004-11-10 13:25:05 UTC
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 21:20:51 UTC
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.