|
Message-ID: <6bac31d90ea71e6151f950f1cc5e6171@anonymousemail.me>
Date: Tue, 16 Aug 2022 18:33:35 +0000
From: Anonymousemail <noreply@...nymousemail.me>
To: musl@...ts.openwall.com
Subject: Broken freopen() does not reset fwide()
I'm using musl based distribution.
The official example from https://en.cppreference.com/w/c/io/fwide is malfunctioning, musl does not reset the fwide(), returns -1 (meaning BYTE oriented).
Output from example on musl:
1) A newly opened stream has no orientation.
no orientation
2) Establish byte orientation.
narrow orientation
narrow character read '#'
wide character read 'i'
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
narrow orientation <- problem detected here, should say "no orientation"
5) Establish wide orientation.
narrow orientation
narrow character read '#'
wide character read 'i'
Another simple example to reproduce the issue.:
#include <stdio.h>
#include <wchar.h>
#include <stdlib.h> // for EXIT_SUCCESS
#include <assert.h>
int main() {
enum { narrow = -1, query = 0, wide = 1 };
FILE* test = fopen("test.bin", "r");
if(!test) {
puts("You need to have test.bin file.");
abort();
}
// establish NARROW orientation
fwide(test, narrow);
// reopen to reset, broken on musl
freopen("test.bin", "r", test);
assert(fwide(test, query) == 0); // will fail on musl
// CLEANUP
fclose(test);
// Exit the program
return EXIT_SUCCESS;
}
-----
Save as main.c, run with
cc main.c
echo test >test.bin
./a.out
Will output
Assertion failed: fwide(test, query) == 0 (main2.c: main: 17)
Aborted
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.