This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/18241] New: failed fseek on memstream does not set errno and can fail when it shouldnt
- From: "nszabolcs at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Fri, 10 Apr 2015 11:57:31 +0000
- Subject: [Bug libc/18241] New: failed fseek on memstream does not set errno and can fail when it shouldnt
- Auto-submitted: auto-generated
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.