musl/src/stdio/vfwscanf.c, branch master musl - an implementation of the standard library for Linux-based systems fix null pointer subtraction and comparison in stdio 2018年09月16日T18:37:22+00:00 Rich Felker dalias@aerifal.cx 2018年09月16日T17:46:46+00:00 849e7603e9004fd292a93df64dd3524025f2987a morally, for null pointers a and b, a-b, a<b, and a>b should all be defined as 0; however, C does not define any of them. the stdio implementation makes heavy use of such pointer comparison and subtraction for buffer logic, and also uses null pos/base/end pointers to indicate that the FILE is not in the corresponding (read or write) mode ready for accesses through the buffer. all of the comparisons are fixed trivially by using != in place of the relational operators, since the opposite relation (e.g. pos>end) is logically impossible. the subtractions have been reviewed to check that they are conditional the stream being in the appropriate reading- or writing-through-buffer mode, with checks added where needed. in fgets and getdelim, the checks added should improve performance for unbuffered streams by avoiding a do-nothing call to memchr, and should be negligible for buffered streams.
morally, for null pointers a and b, a-b, a<b, and a>b should all be
defined as 0; however, C does not define any of them.
the stdio implementation makes heavy use of such pointer comparison
and subtraction for buffer logic, and also uses null pos/base/end
pointers to indicate that the FILE is not in the corresponding (read
or write) mode ready for accesses through the buffer.
all of the comparisons are fixed trivially by using != in place of the
relational operators, since the opposite relation (e.g. pos>end) is
logically impossible. the subtractions have been reviewed to check
that they are conditional the stream being in the appropriate reading-
or writing-through-buffer mode, with checks added where needed.
in fgets and getdelim, the checks added should improve performance for
unbuffered streams by avoiding a do-nothing call to memchr, and should
be negligible for buffered streams.
reduce spurious inclusion of libc.h 2018年09月12日T18:34:37+00:00 Rich Felker dalias@aerifal.cx 2018年09月12日T04:08:09+00:00 5ce3737931bb411a8d167356d4d0287b53b0cbdc libc.h was intended to be a header for access to global libc state and related interfaces, but ended up included all over the place because it was the way to get the weak_alias macro. most of the inclusions removed here are places where weak_alias was needed. a few were recently introduced for hidden. some go all the way back to when libc.h defined CANCELPT_BEGIN and _END, and all (wrongly implemented) cancellation points had to include it. remaining spurious users are mostly callers of the LOCK/UNLOCK macros and files that use the LFS64 macro to define the awful *64 aliases. in a few places, new inclusion of libc.h is added because several internal headers no longer implicitly include libc.h. declarations for __lockfile and __unlockfile are moved from libc.h to stdio_impl.h so that the latter does not need libc.h. putting them in libc.h made no sense at all, since the macros in stdio_impl.h are needed to use them correctly anyway.
libc.h was intended to be a header for access to global libc state and
related interfaces, but ended up included all over the place because
it was the way to get the weak_alias macro. most of the inclusions
removed here are places where weak_alias was needed. a few were
recently introduced for hidden. some go all the way back to when
libc.h defined CANCELPT_BEGIN and _END, and all (wrongly implemented)
cancellation points had to include it.
remaining spurious users are mostly callers of the LOCK/UNLOCK macros
and files that use the LFS64 macro to define the awful *64 aliases.
in a few places, new inclusion of libc.h is added because several
internal headers no longer implicitly include libc.h.
declarations for __lockfile and __unlockfile are moved from libc.h to
stdio_impl.h so that the latter does not need libc.h. putting them in
libc.h made no sense at all, since the macros in stdio_impl.h are
needed to use them correctly anyway.
handle whitespace before %% in scanf 2017年09月04日T20:59:38+00:00 Bartosz Brachaczek b.brachaczek@gmail.com 2017年07月09日T21:00:18+00:00 9255dad97e7bfd4165d1aa0f93f2aae321a7a4d8 this is mandated by C and POSIX standards and is in accordance with glibc behavior.
this is mandated by C and POSIX standards and is in accordance with
glibc behavior.
fix wide scanf's use of a compound literal past its lifetime 2017年03月14日T19:06:58+00:00 Rich Felker dalias@aerifal.cx 2017年03月14日T19:06:58+00:00 733d1ea759119bcd0554f25034d1b4113b910900
fix idiom for setting stdio stream orientation to wide 2015年06月13日T05:17:16+00:00 Rich Felker dalias@aerifal.cx 2015年06月13日T05:17:16+00:00 536c6d5a4205e2a3f161f2983ce1e0ac3082187d the old idiom, f->mode |= f->mode+1, was adapted from the idiom for setting byte orientation, f->mode |= f->mode-1, but the adaptation was incorrect. unless the stream was alreasdy set byte-oriented, this code incremented f->mode each time it was executed, which would eventually lead to overflow. it could be fixed by changing it to f->mode |= 1, but upcoming changes will require slightly more work at the time of wide orientation, so it makes sense to just call fwide. as an optimization in the single-character functions, fwide is only called if the stream is not already wide-oriented.
the old idiom, f->mode |= f->mode+1, was adapted from the idiom for
setting byte orientation, f->mode |= f->mode-1, but the adaptation was
incorrect. unless the stream was alreasdy set byte-oriented, this code
incremented f->mode each time it was executed, which would eventually
lead to overflow. it could be fixed by changing it to f->mode |= 1,
but upcoming changes will require slightly more work at the time of
wide orientation, so it makes sense to just call fwide. as an
optimization in the single-character functions, fwide is only called
if the stream is not already wide-oriented.
fix failure of wide printf/scanf functions to set wide orientation 2014年07月02日T16:09:48+00:00 Rich Felker dalias@aerifal.cx 2014年07月02日T16:09:48+00:00 984c25b74da085c6ae6b44a87bbd5f8afc9be331 in some cases, these functions internally call a byte-based input or output function before calling getwc/putwc, so they cannot rely on the latter to set the orientation.
in some cases, these functions internally call a byte-based input or
output function before calling getwc/putwc, so they cannot rely on the
latter to set the orientation.
include cleanups: remove unused headers and add feature test macros 2013年12月12日T05:09:18+00:00 Szabolcs Nagy nsz@port70.net 2013年12月12日T05:09:18+00:00 571744447c23f91feb6439948f3a619aca850dfb
fix invalid %m format crash in wide scanf variants 2013年09月01日T02:52:41+00:00 Rich Felker dalias@aerifal.cx 2013年09月01日T02:52:41+00:00 f0328a565692320784fa8032f176e40d0998aedd the wide variant was missed in the previous commit.
the wide variant was missed in the previous commit.
fix uninitialized/stale use of alloc (%m modifier) flag in scanf 2013年07月20日T04:21:11+00:00 Rich Felker dalias@aerifal.cx 2013年07月20日T04:21:11+00:00 1d92cddb1e1ed4b6cc0e55461727561e7a2522e0 for conversion specifiers, alloc is always set when the specifier is parsed. however, if scanf stops due to mismatching literal text, either an uninitialized (if no conversions have been performed yet) or stale (from the previous conversion) of the flag will be used, possibly causing an invalid pointer to be passed to free when the function returns.
for conversion specifiers, alloc is always set when the specifier is
parsed. however, if scanf stops due to mismatching literal text,
either an uninitialized (if no conversions have been performed yet) or
stale (from the previous conversion) of the flag will be used,
possibly causing an invalid pointer to be passed to free when the
function returns.
fix scanf %c conversion wrongly storing a terminating null byte 2013年06月22日T21:23:45+00:00 Rich Felker dalias@aerifal.cx 2013年06月22日T21:23:45+00:00 ef5507867b59d19f21437970e87b5d0415c07b2e this seems to have been a regression from the refactoring which added the 'm' modifier.
this seems to have been a regression from the refactoring which added
the 'm' modifier.

AltStyle によって変換されたページ (->オリジナル) /