From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A330385842C; Tue, 21 Mar 2023 11:18:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A330385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679397509; bh=HCSrvpbeO71v7rXWK4gLGn++KSkRAenF6nUyiPfCdk4=; h=From:To:Subject:Date:From; b=Du8z1ojwhJHR7ShNLEpWtAexRB0YOv6oFMwG1IyyMwUejYf24PFO8y3TMHt+OvQiy hezXaB57kWrUxLv9yV9yphDS5wPzTHzM/7G2B5pWX3aiZdITBzY/SZqrVMdhRylLiT g3GSM0ByZ9EmCDm+/LAmQisuF8gWnDktQ95RPhqw= From: "bruno at clisp dot org" To: glibc-bugs@sourceware.org Subject: [Bug stdio/30257] New: *printf of %lc with null argument should not produce a NUL byte Date: Tue, 21 Mar 2023 11:18:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30257 Bug ID: 30257 Summary: *printf of %lc with null argument should not produce a NUL byte Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: stdio Assignee: unassigned at sourceware dot org Reporter: bruno at clisp dot org Target Milestone: --- Created attachment 14769 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D14769&action=3Ded= it test case According to ISO C and POSIX, use of a narrow *printf function with a %lc directive and a (wint_t)0 argument should not produce any output. In glibc, it produces a NUL byte in the output. Citing ISO C 23 =C2=A7 7.23.6.1, description of directive 'c': "If an l length modifier is present, the wint_t argument is converted as if by an ls conversion specification with no precision and an argument that points to storage suitably sized for at least two wchar_t elements, the first element containing the wint_t argument to the lc conversion specification and the second a null wide character." This is essentially unchanged since ISO C 99. Citing POSIX https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/snpr= intf.html : "If an l (ell) qualifier is present, the wint_t argument shall be converted as if by an ls conversion specification with no precision and an argument that points to a two-element array of type wchar_t, the first element of which contains the wint_t argument to the ls [sic!] conversion specification and the second element contains a null wide character." The standards _could_ have specified that the functions produce the multibyte sequence generated by a single wcrtomb call, with a state initialized to zero. This would have made %lc consistent with %c and with the wide *wprintf case. But this is not how the standards did it since 1999 or earlier. A test case is attached. How to reproduce: $ gcc -Wall foo.c $ ./a.out Actual output: ret =3D 2, buf[0] =3D 0x61, buf[1] =3D 0x7a, buf[2] =3D 0x0, buf[3] =3D 0xdd ret =3D 3, buf[0] =3D 0x61, buf[1] =3D 0x0, buf[2] =3D 0x7a, buf[3] =3D 0x0 Expected output (so far, only musl libc gets it right): ret =3D 2, buf[0] =3D 0x61, buf[1] =3D 0x7a, buf[2] =3D 0x0, buf[3] =3D 0xdd ret =3D 2, buf[0] =3D 0x61, buf[1] =3D 0x7a, buf[2] =3D 0x0, buf[3] =3D 0xdd --=20 You are receiving this mail because: You are on the CC list for the bug.=