mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rob Landley <rob@landley.net>
To: musl@lists.openwall.com
Subject: [musl] strftime trailing %
Date: Mon, 19 Dec 2022 12:06:38 -0600	[thread overview]
Message-ID: <a8b5e402-e92a-080f-dd4f-c2c70ba756d2@landley.net> (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;
 			continue;
 		}

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

Rob

             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:
  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=a8b5e402-e92a-080f-dd4f-c2c70ba756d2@landley.net \
    --to=rob@landley.net \
    --cc=musl@lists.openwall.com \
    /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).