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 libc/18241] New: failed fseek on memstream does not set errno and can fail when it shouldnt


https://sourceware.org/bugzilla/show_bug.cgi?id=18241

            Bug ID: 18241
           Summary: failed fseek on memstream does not set errno and can
                    fail when it shouldnt
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: nszabolcs at gmail dot com
                CC: drepper.fsp at gmail dot com

it seems fseek does not work as it should on memstreams opened by
open_memstream and fmemopen:

fseek outside of the bounds fails but does not set errno to EINVAL.

fseek(f,-1,SEEK_CUR) fails.


the code below prints:
errno == EINVAL failed
  errno = Success
fseek(f, -1, SEEK_CUR) >= 0 failed
ftell(f) == 0 failed
strcmp(s, "b") == 0 failed
  s = "ab"


#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <string.h>
#include <stdio.h>

#define A(x) ((x) || (printf(#x " failed\n"),0))

int main(void)
{
FILE *f;
char *s;
size_t l;

f = open_memstream(&s, &l);
A(f);
A(putc('a', f) == 'a');
A(fflush(f) == 0);
A(fseek(f, -2, SEEK_CUR) == -1);
A(errno == EINVAL) || printf("  errno = %s\n", strerror(errno));
A(ftell(f) == 1);
A(ferror(f) == 0);

A(fseek(f, -1, SEEK_CUR) >= 0) || printf("  errno = %s\n", strerror(errno));
A(ftell(f) == 0);
A(ferror(f) == 0);
A(putc('b', f) == 'b');
A(fflush(f) == 0);
A(strcmp(s, "b") == 0) || printf("  s = \"%s\"\n", s);
}

-- 
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]