Skip to content

Commit 5468973

Browse files
committed
Handle trailing % in strftime
"In glibc a trailing % in strftime() acts like printf, ie it's a literal %". This is breaking some Python tests. I've applied the patch suggested here: https://www.openwall.com/lists/musl/2022/12/19/2
1 parent 06cebfc commit 5468973

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

system/lib/libc/musl/src/time/strftime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st
226226
s[l] = 0;
227227
return l;
228228
}
229-
if (*f != '%') {
229+
if (*f != '%' || !f[1]) {
230230
s[l++] = *f;
231231
continue;
232232
}

test/other/test_strftime.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,8 @@ int main() {
307307
size = strftime(s, sizeof(s), "%Ec", &tm);
308308
TEST(!cmp(s, "Mon Dec 17 00:00:00 2018"), "strftime test #36a", s);
309309

310+
size = strftime(s, sizeof(s), "trailing %", &tm);
311+
TEST((size == 10), "strftime test #37", s);
312+
TEST(!cmp(s, "trailing %"), "strftime test #37", s);
310313
return 0;
311314
}

0 commit comments

Comments
 (0)