Date: Sun, 10 Sep 2023 18:41:23 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@FreeBSD.org> To: Warner Losh <imp@bsdimp.com> Cc: Robert Clausecker <fuz@fuz.su>, FreeBSD Current <current@freebsd.org> Subject: Re: sed in CURRENT fails in textproc/jq Message-ID: <861qf6q8uk.fsf@ltc.des.no> In-Reply-To: <CANCZdfoCBXxNzfTQ03bHwgOkRMoZAAkj_yxZ58i82e0chMWEog@mail.gmail.com> (Warner Losh's message of "Sun, 10 Sep 2023 09:53:03 -0600") References: <30a59ac0-28fd-f6ed-505c-9ef6d8e84fc3@tsoft.com> <CAALwa8kAaDw80h2cbaeLOmw2G9EpRo6dJFZcFFc99mAU_7xkRA@mail.gmail.com> <86edj7qnia.fsf@ltc.des.no> <ZP1LPZcC99zIS1Jp@fuz.su> <CANCZdfpesLu%2B5YLB4-irR7XSSSM1wXPLH58TbefPzvGo=q1xgg@mail.gmail.com> <ZP3GWo3ZXahC8_2_@fuz.su> <CANCZdfoCBXxNzfTQ03bHwgOkRMoZAAkj_yxZ58i82e0chMWEog@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Warner Losh <imp@bsdimp.com> writes: > As for memchr, https://pubs.opengroup.org/onlinepubs/009696799/functions/= memchr.html > has no such permission to examine 'the entire buffer at once' nor any res= tirction > as to the length extending beyond the address space. I'm skeptical of you= r reading > that it allows one to examine all of [b, b + len), so please explain wher= e the standard > supports reading past the first occurance. C11 says: (7.24.4.1 =C2=A72) The memcmp function compares the first n characters = of the object pointed to by s1 to the first n characters of the object pointed to by s2. and (7.24.5.1 =C2=A72) The memchr function locates the first occurrence of c (converted to an unsigned char) in the initial n characters (each interpreted as unsigned char) of the object pointed to by s. The implementation shall behave as if it reads the characters sequentially and stops as soon as a matching character is found. The second sentence in the description of memchr() means a bogus length is allowed as long as we get a match before we read past the end of the object. There is no such provision for memcmp(), so calling memcmp() with a bogus length invokes UB. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?861qf6q8uk.fsf>