mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rob Landley <>
Subject: [musl] strftime trailing %
Date: Mon, 19 Dec 2022 12:06:38 -0600	[thread overview]
Message-ID: <> (raw)

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;

This is breaking a toybox test for the "date" command.


             reply	other threads:[~2022-12-19 17:55 UTC|newest]

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

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:

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

  git send-email \ \ \ \

* 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

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).