tool_writeout: check strftime() return code

Because if it fails, the contents of the output buffer is undefined.

Pointed out by CodeSonar

Also polished the documentation

Follow-up to fadc487567

Closes #18220
This commit is contained in:
Daniel Stenberg 2025-08-07 15:43:25 +02:00
parent 10e60e825c
commit 16eac53dc9
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 26 additions and 16 deletions

View file

@ -603,8 +603,9 @@ static const char *outtime(const char *ptr, /* %time{ ... */
if(!result) {
/* !checksrc! disable BANNEDFUNC 1 */
utc = gmtime(&secs);
strftime(output, sizeof(output), curlx_dyn_ptr(&format), utc);
fputs(output, stream);
if(curlx_dyn_len(&format) &&
strftime(output, sizeof(output), curlx_dyn_ptr(&format), utc))
fputs(output, stream);
curlx_dyn_free(&format);
}
ptr = end + 1;