mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Rob Landley <rob@landley.net>
Cc: musl@lists.openwall.com
Subject: Re: [musl] strftime trailing %
Date: Mon, 19 Dec 2022 13:50:58 -0500	[thread overview]
Message-ID: <20221219185057.GD15716@brightrain.aerifal.cx> (raw)
In-Reply-To: <a8b5e402-e92a-080f-dd4f-c2c70ba756d2@landley.net>

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 <stdio.h>
> #include <time.h>
> 
> 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

      reply	other threads:[~2022-12-19 18:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 18:06 Rob Landley
2022-12-19 18:50 ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221219185057.GD15716@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=rob@landley.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).