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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25008 invoked from network); 19 Dec 2022 18:51:14 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 19 Dec 2022 18:51:14 -0000 Received: (qmail 27660 invoked by uid 550); 19 Dec 2022 18:51:11 -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 26601 invoked from network); 19 Dec 2022 18:51:11 -0000 Date: Mon, 19 Dec 2022 13:50:58 -0500 From: Rich Felker To: Rob Landley Cc: musl@lists.openwall.com Message-ID: <20221219185057.GD15716@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] strftime trailing % On Mon, Dec 19, 2022 at 12:06:38PM -0600, Rob Landley wrote: > In glibc and bionic a trailing % in strftime() acts like printf, I.E. it's a > literal "%". But in musl, it's an error that returns length 0. Test program: > > #include > #include > > int main(int argc, char *argv[]) > { > char buf[256]; > struct tm tm = {0}; > > strftime(buf, sizeof(buf), "hello %", &tm); > return printf("%s\n", buf); > } > > > The fix looks simple enough, although I haven't built a toolchain with it yet: > > --- a/src/time/strftime.c > +++ b/src/time/strftime.c > @@ -225,7 +225,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char > *restrict f, const st > s[l] = 0; > return l; > } > - if (*f != '%') { > + if (*f != '%' || !f[1]) { > s[l++] = *f; > continue; > } > > This is breaking a toybox test for the "date" command. Is this supposed to be well-defined, either for the date command or for strftime? I don't see where it's explicitly covered in any of the spec so if it's defined or undefined/unspecified would presumably fall out as a consequence of how conversion specifications and ordinary characters are defined. Rich