From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id C7765385742B for ; Mon, 16 Aug 2021 16:42:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7765385742B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id CB1ED3F2FFE0; Mon, 16 Aug 2021 09:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1629132136; bh=dG5bVeJPeFASizwb2BrBmt14wjrfQc0sh+OnL57vaSM=; h=From:To:Subject:In-Reply-To:References:Date:From; b=m5/aWvpkpgweApBAhwbvhLjXs6HgUHt7b81ihUG7RMdmLPsXtA/VNP+wCTJrNlo0W Kw4vJr+Zx5UwfkA2OW7kznzMti3OunLBkNh9SkgwfwBT5/9UC/BQ/YsbCjgYT1C24b gN8KCV9XlRbFzgOu+saMOYNiocNi4aTHOWj38i/0TBehdVN+k94dSQvmkWNZYyOMiq M5V+dPN0TyrW/YpT3PlW/qxZePzvC+z420K4WRpCj2yTp/l+CWrtwISCBH8jji6H8q Qfd5IuONYQ//fBblS3wSrFyne2oiOOjG2J25dv27VpkJYPfZt2ZM5hf2VJ49Aya75N G1DDXZswzdClw== X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id cdLk7GcvIj3f; Mon, 16 Aug 2021 09:42:12 -0700 (PDT) Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 07F323F2FF6F; Mon, 16 Aug 2021 09:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1629132132; bh=dG5bVeJPeFASizwb2BrBmt14wjrfQc0sh+OnL57vaSM=; h=From:To:Subject:In-Reply-To:References:Date:From; b=nuLQ6hJ8b8kPrcsvEOv1Uxf1eiySzKc86qn3NUr8jwszxvqjOty0ndSUGnrggj3r9 DEoh+52s2dgLP2yYlVf2rzUJhAFro/lcJ3d+y8tOanTpXaR8G1ZuXn8NByi0sGxl7e SuzlLh/p5cbJos+2h0dWMGFR/SR80tV3XWj7gkrXoJRYIvBOGZBaYbbiPNIqbzugaA 8aqujQxdNcO41K81YJwBXXqqNOtehgMYPFZkE9HTJ4Gs5TxwzPTyHHOvMhFUH+iPP0 EDfnSAWUG5GgzSQDdmH0lxg1NIlE7plZaYEvbUZwcb5PWZhWiCqFADV0bTajLKTCRx 7wFBVTnVRbmrQ== Received: by keithp.com (Postfix, from userid 1000) id E17831E6011A; Mon, 16 Aug 2021 09:42:34 -0700 (PDT) From: Keith Packard To: Alexandre Raymond , newlib@sourceware.org Subject: Re: Issue with sscanf not parsing correctly In-Reply-To: References: Date: Mon, 16 Aug 2021 09:42:34 -0700 Message-ID: <87czqdfiit.fsf@keithp.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 16:42:51 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Alexandre Raymond writes: > Greetings! > > I have been developing on a Teensy 4.1 platform, which I'm told uses > newlib under the hood, and encountered a strange issue with sscanf, > where different parameter orderings yield different results with > stdint types. Odd. I've just tested this using the qemu model for the thumb_v7e_m_dp_hard gcc target for the picolibc build set to use the legacy stdio bits from newlib and it seems to work just fine (it also works fine with the new stdio bits from picolibc). Could this libc be built to not support C99 formats? That would cause all kinds of issues as sscanf would fail when it hit the '%hhu' format. Here's the regular C test code I used for this: --=-=-= Content-Type: text/x-csrc Content-Disposition: inline; filename=sscanf-order.c #include #include #include #include void __assert_func(const char *file, int line, const char *func, const char *expr) { printf("%s:%d (%s) assertion failed: %s\n", file, line, func, expr); exit(1); } int main(void) { uint8_t i2c_addr = 1; uint16_t mem_addr = 1; uint8_t len = 1; int ret; printf("%d, %d, %d\n", i2c_addr, mem_addr, len); //prints: 1,1,1 const char *cmd = "1 2 3\n"; // This is the order I intended to scan the string in ret = sscanf(cmd, "%hhu %hu %hhu", &i2c_addr, &mem_addr, &len); printf("%d- %d, %d, %d\n", ret, i2c_addr, mem_addr, len); assert(i2c_addr ==1 && mem_addr == 2 && len == 3); // prints: 3- 1,0,3 // I just swap the order of the target variables around ret = sscanf(cmd, "%hhu %hhu %hu", &i2c_addr, &len, &mem_addr); printf("%d- %d, %d, %d\n", ret, i2c_addr, len, mem_addr); assert(i2c_addr ==1 && len == 2 && mem_addr == 3); // prints: 3- 1,2,3 return 0; } --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable I've added this as a picolibc test so it will be regularly checked against both newlib and picolibc stdio bits going forward. =2D-=20 =2Dkeith --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAmEalXoACgkQ2yIaaQAA ABEdCw/5Acbujr4vfL4Qj07mSKDllDKLG1XiA/oxo59JOh0/3WDABm2+DOLEdHtD UPNCPO7vmJfljrrbhzmJuTZatGFCd+pXIfnc6Mg7wTIB+HSTVsLBW48NanB+pvU+ FNRJRBVWE3Y/96/TAtw9AcarqaE7cOx+3nLqEfwh7hXgh4a6UZo68RzPActZquPN yCThJzTucCMQ22/voVE91MEgucXP59RGbHATUDU3s8vVPHWicOtzkaCzRIqhcTCL SEqsFGkYAZpXmDrv4jWYszMYoxmZWlFvyASqljI1fnbhl6NmGMTo9adLfTZZqa5y sq5mLogi9n22CctrFdxw//meTwGV+i3OwjhbfeOW5iUKM58ZA4fa73S4vYLFpdOd Wm1kENshL+ThpFWSY3J1wJIRs66oqhGuB5orlFnAvG6ogLyPsocCRUbFnmgi892L xkI8oh7ngdfJtiyK3V9XUPcNZfGZUh4KceLJSrAF+Q6PQvWVcEFNAa+rwTuw8XMp tALRr1lsBEOLHpNUDW/7rGdNUxXkbPOWJVVmnM49J1k7AhmHzvKvBsW35EJv8dzK KnQJQGSVBitk4H+NV4WHF3baenlnzCjmj7cKpgKKL4FVW+ZevPvR3MRIRpWtodhJ C0Q0VH6onHmYxgMs5I9OdCOtrf28bksFLH5oeKknsSOiWiOh0o8= =WhZI -----END PGP SIGNATURE----- --==-=-=--