From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7672 invoked from network); 13 Jul 2021 14:53:47 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Jul 2021 14:53:47 -0000 Received: (qmail 19755 invoked by uid 550); 13 Jul 2021 14:53:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 19734 invoked from network); 13 Jul 2021 14:53:44 -0000 X-Virus-Scanned: Debian amavisd-new at disroot.org Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1626188010; bh=p0mti4oFIOJDLFaEWX9Myz8MI9jZ0qF/KXbI7i1GD8g=; h=Subject:From:To:Date:In-Reply-To; b=FbxQItH1xBdPh20vuUH5AHn4xtS9PPNeNPGZRu+5hWlqOwsf8w4o5w/Zdxed9Emfv mkJNOK53FTQQN/T8kESfgGwG6wb4CRrojMJj47fv0/Qx+aEadsC+q+vHJS+tcIGNC3 hdYwIDG5od4KfE3blL5wsAu6bbPsd16oEOt+4KrFKq6obMez6KW1uhBk9RjQdZW/la YjeoJeIjX3n42DgS9oxCLoOt24LQobs92acvOrSHjaWfzC7mvlfIrWKIFDk6Ib0Tlm Q4zmtCCGtoncpXkm759bUIzedQMcXbMEN59HwIoTgT3RCyu4VPC7I9mb+2jggCfCcr FhIcTdmEcwhxA== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 From: =?utf-8?q?=C3=89rico_Nogueira?= To: Date: Tue, 13 Jul 2021 11:49:35 -0300 Message-Id: In-Reply-To: <0F84CB3415BB437FBD48B8B81795064E@H270> Subject: Re: [musl] Changes for strcspn(), strspn(), strtok() and strtok_r() On Tue Jul 13, 2021 at 9:02 AM -03, Stefan Kanthak wrote: > > > #include > =20 > #define BITOP(a,b,op) \ > ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof > *(a)))) > =20 > -size_t strcspn(const char *s, const char *c) > +size_t strcspn(const char *restrict s, const char *c) > { > - const char *a =3D s; > + const char *a; > - size_t byteset[32/sizeof(size_t)]; > + size_t byteset[32/sizeof(size_t)] =3D { 0 }; > =20 > - if (!c[0] || !c[1]) return __strchrnul(s, *c)-a; > + if (!c[0] || !c[1]) return __strchrnul(a=3Ds, *c)-a; This is unspecified behavior and could lead to UB (reading from uninitialized a). musl enables -Wsequence-point, so building with --enable-warnings is important to catch such issues. > =20 > - memset(byteset, 0, sizeof byteset); > for (; *c && BITOP(byteset, *(unsigned char *)c, |=3D); c++); > - for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); > - return s-a; > + for (a=3Ds; *a && !BITOP(byteset, *(unsigned char *)a, &); a++); > + return a-s; > }