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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8544 invoked from network); 20 Mar 2023 00:30:03 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Mar 2023 00:30:03 -0000 Received: (qmail 28644 invoked by uid 550); 20 Mar 2023 00:30:00 -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 28611 invoked from network); 20 Mar 2023 00:29:59 -0000 ARC-Seal: i=1; a=rsa-sha256; t=1679272187; cv=none; d=strato.com; s=strato-dkim-0002; b=snSSWhDNtppTFoUdwtiZ8jGcJaxXt4b32HQsY931k4W4hFga7X/zOuJCWsx8IAJqtr pgJbu5lTqvz7r5Q45nMiYcTCynn93AyFAR2thqvA2ngH/0LUKQXSED3aPZNokjI4e0VP G8fM8PmVclygkCgrVANgMQGwN6YagHiYkmixh+0uDp0cipHqF+oAB/siL4OuH71hD65c qOhXHzpy2LGRab4kT/sX+erWDQ4bDcgSgr1uZNry1FsiW3KhAq4wG3lVj/alXqnmMmdi lp5NldE5/jqqxK4Ph/GPHYIvnkgO/bQMmcLJ4iydrQMwbT8Yf4b3clsICYX4Q/ghRBOj sLYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1679272187; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=4mSQKcdvSnMkjuccbb/IaRL7SkwZM1nntMclEwlIr/g=; b=XJ7oobJ5s77W5JO+D4+09RHDZJkpskSjt/W0avwkQD/lajzyoG2HOmp8yJ74qsSpXh FlS208LG1c68nrOIZr8Dh0vm/wwhMoiy1nE96lXk0oHqWwuFl9DxClMG9fsv2bJRmzX1 cn0J2q/SIx77C5moERfYcYZsXEltdtvjhB6iSeytzwivWWPfRr6UQPXkNS/kZOheub5Y DglH98KITSygkbIcr/QVGCEDYtYLS9SMX2lYi8MuX3bDToCAyp5Se4vqRJYtCGqg062q AY5K10XCxxJEAL+R//LLbX4A0V5j12Nx8J8MPErahGTr4YgrcNgua5ICx5ZfWlb+CctE TIPQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1679272187; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=4mSQKcdvSnMkjuccbb/IaRL7SkwZM1nntMclEwlIr/g=; b=Opp5JUBWWJWj43CoPJaKsGVbEbEZ7VDpqU7cycWZL14fX2xhRB3Jiom316F1nwOLGl 0ZkLLJ7WoQAUKokCOE8zIvLjst1sW/jB+Cwobjf0scxFan2m09aLajArHyE3eo9f/WyT hF3K2wOZPxvOoVI0Tl9PWHmGB6WwRatVwXCbf4XJgkDG1qcMwmYcNuKSKjuj3XyOpkcg c01yTu9CpiaGl0gOK0r0Rz4m/R0dwkA4Uo5DPXe9nf73TXCqfnWzIfzb8NVODxnqS4Hn sNWTHBnSdlvsHjIgKDxa5Rsod9IgZA/e4HL8EU9PGeX0YkzDgzZvEZZseWJfeRwsN2tK Z10A== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LNUXbYz27Dm57lGjAq13ulkEiKPsDODB1WZ088XdO7Ef9X0=" From: Bruno Haible To: musl@lists.openwall.com Date: Mon, 20 Mar 2023 01:29:47 +0100 Message-ID: <11995006.zapYfy813O@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: [musl] swprintf: minimum width ignored for %lc On musl-1.2.3 I see this violation of the POSIX specification of swprintf [1]: ==================================== foo1.c ==================================== #include #include int main () { static wint_t L_x = (wchar_t) 'x'; wchar_t buf[12] = { 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF }; int ret = swprintf (buf, 12, L"%10lc", L_x); printf ("ret = %d, buf[0] = 0x%x, buf[1] = 0x%x, buf[9] = 0x%x, buf[10] = 0x%x, buf[11] = 0x%x\n", ret, (unsigned int) buf[0], (unsigned int) buf[1], (unsigned int) buf[9], (unsigned int) buf[10], (unsigned int) buf[11]); return 0; } /* glibc: ret = 10, buf[0] = 0x20, buf[1] = 0x20, buf[9] = 0x78, buf[10] = 0x0, buf[11] = 0xdeadbeef musl libc: ret = 1, buf[0] = 0x78, buf[1] = 0x0, buf[9] = 0xdeadbeef, buf[10] = 0xdeadbeef, buf[11] = 0xdeadbeef */ ================================================================================ $ gcc -Wall foo1.c $ ./a.out ret = 1, buf[0] = 0x78, buf[1] = 0x0, buf[9] = 0xdeadbeef, buf[10] = 0xdeadbeef, buf[11] = 0xdeadbeef The POSIX specification [1] says: "An optional minimum field width. If the converted value has fewer wide characters than the field width, it shall be padded with characters by default on the left; it shall be padded on the right, if the left- adjustment flag ( '-' ), described below, is given to the field width. The field width takes the form of an ( '*' ), described below, or a decimal integer." Here, the minimum field width specification of 10 was apparently ignored. For comparison, in snprintf, this case is handled correctly: ==================================== foo2.c ==================================== #include #include #include int main () { static wint_t L_x = (wchar_t) 'x'; char buf[12] = { 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD }; int ret = snprintf (buf, 12, "%10lc", L_x); printf ("ret = %d, buf[0] = 0x%x, buf[1] = 0x%x, buf[9] = 0x%x, buf[10] = 0x%x, buf[11] = 0x%x\n", ret, (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]); return 0; } /* glibc: ret = 10, buf[0] = 0x20, buf[1] = 0x20, buf[9] = 0x78, buf[10] = 0x0, buf[11] = 0xdd musl libc: ret = 10, buf[0] = 0x20, buf[1] = 0x20, buf[9] = 0x78, buf[10] = 0x0, buf[11] = 0xdd */ ================================================================================ $ gcc -Wall foo1.c $ ./a.out ret = 10, buf[0] = 0x20, buf[1] = 0x20, buf[9] = 0x78, buf[10] = 0x0, buf[11] = 0xdd Bruno [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/swprintf.html