musl/src/stdio/ext2.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.
fix issues from public functions defined without declaration visible 2018年09月12日T18:34:20+00:00 Rich Felker dalias@aerifal.cx 2018年09月06日T15:15:15+00:00 c221d3e5862e249b03aa7569d5fec6389294fb22 policy is that all public functions which have a public declaration should be defined in a context where that public declaration is visible, to avoid preventable type mismatches. an audit performed using GCC's -Wmissing-declarations turned up the violations corrected here. in some cases the public header had not been included; in others, a feature test macro needed to make the declaration visible had been omitted. in the case of gethostent and getnetent, the omission seems to have been intentional, as a hack to admit a single stub definition for both functions. this kind of hack is no longer acceptable; it's UB and would not fly with LTO or advanced toolchains. the hack is undone to make exposure of the declarations possible.
policy is that all public functions which have a public declaration
should be defined in a context where that public declaration is
visible, to avoid preventable type mismatches.
an audit performed using GCC's -Wmissing-declarations turned up the
violations corrected here. in some cases the public header had not
been included; in others, a feature test macro needed to make the
declaration visible had been omitted.
in the case of gethostent and getnetent, the omission seems to have
been intentional, as a hack to admit a single stub definition for both
functions. this kind of hack is no longer acceptable; it's UB and
would not fly with LTO or advanced toolchains. the hack is undone to
make exposure of the declarations possible.
fix invalid implicit pointer conversion in gnulib-compat functions 2012年09月07日T03:27:55+00:00 Rich Felker dalias@aerifal.cx 2012年09月07日T03:27:55+00:00 453059571c9dc84dd168631eced25ec2d7afd98e
add new stdio extension functions to make gnulib happy 2012年06月19日T05:35:23+00:00 Rich Felker dalias@aerifal.cx 2012年06月19日T05:35:23+00:00 e15171b8d8e80e8b5bcf4e95b1709697858f545a this is mildly ugly, but less ugly than gnulib trying to poke at the definition of the FILE structure...
this is mildly ugly, but less ugly than gnulib trying to poke at the
definition of the FILE structure...

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