strftime: fix breakage in last change (uninitialized pointer access)

commit f47a5d400b overlooked that
strtoul was responsible for setting p to a const-laundered copy of the
format string pointer f, even in the case where there was no number to
parse. by making the call conditional on isdigit, that copy was lost.

the logic here is a mess and should be cleaned up, but for now, this
seems to be the least invasive change that undoes the breakage.
This commit is contained in:
Rich Felker 2024-02-12 17:35:48 -05:00
parent cf91e9b393
commit 4a16ddf53e

View file

@ -234,7 +234,12 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st
pad = 0;
if (*f == '-' || *f == '_' || *f == '0') pad = *f++;
if ((plus = (*f == '+'))) f++;
width = isdigit(*f) ? strtoul(f, &p, 10) : 0;
if (isdigit(*f)) {
width = strtoul(f, &p, 10);
} else {
width = 0;
p = (void *)f;
}
if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') {
if (!width && p!=f) width = 1;
} else {