This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/14543] New: fseek sets invalid status in the internal buffer in wide mode


http://sourceware.org/bugzilla/show_bug.cgi?id=14543

             Bug #: 14543
           Summary: fseek sets invalid status in the internal buffer in
                    wide mode
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
        AssignedTo: unassigned@sourceware.org
        ReportedBy: siddhesh@redhat.com
    Classification: Unclassified


fseek sets the pointers in the external buffer correctly, but initializes the
internal buffer as if there's nothing in it. As a result, the position computed
in a subsequent ftell is incorrect.

How Reproducible:

Always

Reproducer program:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(int argc, char** argv)
{
    FILE *fp;

    setlocale(LC_ALL, "en_US.utf8");
    fp = fopen("output.txt", "w+");
    if (fp == NULL) {
        perror("fopen");
        exit(1);
    }
    if (fputws(L"abc\n", fp) == -1) {
        perror("fputws");
        exit(1);
    }
    printf("before=%d\n", ftell(fp));
    rewind (fp);
    if (fseek(fp, 0L, SEEK_END) == -1) {
        perror("fseek");
        exit(1);
    }
    printf("fseek=%d\n", ftell(fp));
    if (fputws(L"xyz\n", fp) == -1) {
        perror("fputws");
        exit(1);
    }
    printf("after=%d\n", ftell(fp));
    fclose(fp);
}

Actual result:

before=4
fseek=0
after=4

Expected Result:

before=4
fseek=4
after=8

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]