musl/src/string/strstr.c, branch master musl - an implementation of the standard library for Linux-based systems fix misleading comment in strstr 2020年12月09日T16:34:29+00:00 Rich Felker dalias@aerifal.cx 2020年12月09日T16:34:29+00:00 c53e9b239418eb3e0e8be256abd0f6ad7608bbcf the intent here is just to scan at least l bytes forward for the end of the haystack and at least some decent minimum to avoid doing it over and over if the needle is short, with no need to be precise. the comment erroneously stated this as an estimate for MIN when it's actually an estimate for MAX.
the intent here is just to scan at least l bytes forward for the end
of the haystack and at least some decent minimum to avoid doing it
over and over if the needle is short, with no need to be precise. the
comment erroneously stated this as an estimate for MIN when it's
actually an estimate for MAX.
fix undefined behavior from signed overflow in strstr and memmem 2020年05月01日T01:52:28+00:00 Rich Felker dalias@aerifal.cx 2020年05月01日T01:36:43+00:00 593caa456309714402ca4cb77c3770f4c24da9da unsigned char promotes to int, which can overflow when shifted left by 24 bits or more. this has been reported multiple times but then forgotten. it's expected to be benign UB, but can trap when built with explicit overflow catching (ubsan or similar). fix it now. note that promotion to uint32_t is safe and portable even outside of the assumptions usually made in musl, since either uint32_t has rank at least unsigned int, so that no further default promotions happen, or int is wide enough that the shift can't overflow. this is a desirable property to have in case someone wants to reuse the code elsewhere.
unsigned char promotes to int, which can overflow when shifted left by
24 bits or more. this has been reported multiple times but then
forgotten. it's expected to be benign UB, but can trap when built with
explicit overflow catching (ubsan or similar). fix it now.
note that promotion to uint32_t is safe and portable even outside of
the assumptions usually made in musl, since either uint32_t has rank
at least unsigned int, so that no further default promotions happen,
or int is wide enough that the shift can't overflow. this is a
desirable property to have in case someone wants to reuse the code
elsewhere.
optimize two-way strstr and memmem bad character shift 2018年11月08日T20:22:22+00:00 Rich Felker dalias@aerifal.cx 2018年11月08日T20:00:02+00:00 122d67f846cb0be2c9e1c3880db9eb9545bbe38c first, the condition (mem && k < p) is redundant, because mem being nonzero implies the needle is periodic with period exactly p, in which case any byte that appears in the needle must appear in the last p bytes of the needle, bounding the shift (k) by p. second, the whole point of replacing the shift k by mem (=l-p) is to prevent shifting by less than mem when discarding the memory on shift, in which case linear time could not be guaranteed. but as written, the check also replaced shifts greater than mem by mem, reducing the benefit of the shift. there is no possible benefit to this reduction of the shift; since mem is being cleared, the full shift is valid and more optimal. so only replace the shift by mem when it would be less than mem.
first, the condition (mem && k < p) is redundant, because mem being
nonzero implies the needle is periodic with period exactly p, in which
case any byte that appears in the needle must appear in the last p
bytes of the needle, bounding the shift (k) by p.
second, the whole point of replacing the shift k by mem (=l-p) is to
prevent shifting by less than mem when discarding the memory on shift,
in which case linear time could not be guaranteed. but as written, the
check also replaced shifts greater than mem by mem, reducing the
benefit of the shift. there is no possible benefit to this reduction of
the shift; since mem is being cleared, the full shift is valid and
more optimal. so only replace the shift by mem when it would be less
than mem.
remove commented-out debug printf from strstr 2018年11月02日T16:04:41+00:00 Rich Felker dalias@aerifal.cx 2018年11月02日T16:04:41+00:00 0239cd0681e889a269fb7691f60e81ef8d081e6b this was leftover from before the initial commit.
this was leftover from before the initial commit.
fix spuriously slow check in twoway strstr/memmem cores 2018年11月02日T16:02:09+00:00 Rich Felker dalias@aerifal.cx 2018年11月02日T16:01:37+00:00 8f5a820d147da36bcdbddd201b35d293699dacd8 mem0 && mem && ... is redundant since mem can only be nonzero when mem0 is nonzero.
mem0 && mem && ... is redundant since mem can only be nonzero when
mem0 is nonzero.
fix false negatives with periodic needles in strstr, wcsstr, and memmem 2014年04月18日T21:38:35+00:00 Rich Felker dalias@aerifal.cx 2014年04月18日T21:38:35+00:00 476cd1d96560aaf7f210319597556e7fbcd60469 in cases where the memorized match range from the right factor exceeded the length of the left factor, it was wrongly treated as a mismatch rather than a match. issue reported by Yves Bastide.
in cases where the memorized match range from the right factor
exceeded the length of the left factor, it was wrongly treated as a
mismatch rather than a match.
issue reported by Yves Bastide.
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
remove unused but buggy code from strstr.c 2012年08月11日T22:40:33+00:00 Rich Felker dalias@aerifal.cx 2012年08月11日T22:40:33+00:00 f997e224fc30361fe683c6b5d0ba39718043ca8d
fix all implicit conversion between signed/unsigned pointers 2011年03月25日T20:34:03+00:00 Rich Felker dalias@aerifal.cx 2011年03月25日T20:34:03+00:00 9ae8d5fc71a4b61ec826d58f03f7b543755fb1d4 sadly the C language does not specify any such implicit conversion, so this is not a matter of just fixing warnings (as gcc treats it) but actual errors. i would like to revisit a number of these changes and possibly revise the types used to reduce the number of casts required.
sadly the C language does not specify any such implicit conversion, so
this is not a matter of just fixing warnings (as gcc treats it) but
actual errors. i would like to revisit a number of these changes and
possibly revise the types used to reduce the number of casts required.
initial check-in, version 0.5.0 2011年02月12日T05:22:29+00:00 Rich Felker dalias@aerifal.cx 2011年02月12日T05:22:29+00:00 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01

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