mirror of
https://github.com/fluencelabs/musl
synced 2025-06-25 12:42:02 +00:00
avoid hitting eof in wcstol
shunget cannot unget eof status, causing wcstol to leave endptr pointing to the wrong place when scanning, for example, L"0x". cheap fix is to make the read function provide an infinite stream of bogus characters rather than eof. really this is something of a design flaw in how the shgetc system is used for strto* and wcsto*; in the long term, I believe multi-character unget should be scrapped and replaced with a function that can subtract from the f->shcnt counter.
This commit is contained in:
@ -11,6 +11,7 @@ static size_t do_read(FILE *f, unsigned char *buf, size_t len)
|
|||||||
size_t i;
|
size_t i;
|
||||||
const wchar_t *wcs = f->cookie;
|
const wchar_t *wcs = f->cookie;
|
||||||
|
|
||||||
|
if (!wcs[0]) wcs=L"@";
|
||||||
for (i=0; i<f->buf_size && wcs[i]; i++)
|
for (i=0; i<f->buf_size && wcs[i]; i++)
|
||||||
f->buf[i] = wcs[i] < 128 ? wcs[i] : '@';
|
f->buf[i] = wcs[i] < 128 ? wcs[i] : '@';
|
||||||
f->rpos = f->buf;
|
f->rpos = f->buf;
|
||||||
@ -30,8 +31,8 @@ static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsign
|
|||||||
FILE f = {0};
|
FILE f = {0};
|
||||||
f.flags = 0;
|
f.flags = 0;
|
||||||
f.rpos = f.rend = 0;
|
f.rpos = f.rend = 0;
|
||||||
f.buf = buf;
|
f.buf = buf + 4;
|
||||||
f.buf_size = sizeof buf;
|
f.buf_size = sizeof buf - 4;
|
||||||
f.lock = -1;
|
f.lock = -1;
|
||||||
f.read = do_read;
|
f.read = do_read;
|
||||||
f.cookie = (void *)s;
|
f.cookie = (void *)s;
|
||||||
|
Reference in New Issue
Block a user