ref: 1d263bb8b0a2b372050ec285a1306431c203542e
parent: 7e4b96f8949a4dc2e1da9a003b148ab0973123b0
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue May 17 09:21:48 EDT 2022
libc: Fix return value in strftime() It must return 0 when there is truncation in the output buffer.
--- a/src/libc/time/strftime.c
+++ b/src/libc/time/strftime.c
@@ -169,9 +169,10 @@
{
int ch, abrev, val, fill, width;
size_t n, inc;
- char *tfmt;
+ char *tfmt, *begin;
- for (n = --maxsize; (ch = *format++) && n > 0; s += inc, n -= inc) {
+ begin = s;
+ for (n = maxsize; (ch = *format++) && n > 0; s += inc, n -= inc) {
if (ch != '%') {
*s = ch;
inc = 1;
@@ -320,7 +321,11 @@
break;
}
}
+
+ n = s - begin;
+ if (n == maxsize)
+ return 0;
*s = '\0';
- return maxsize - n;
+ return n;
}