Skip to content

mprintf: use _snprintf() when compiled with VS2013 and older#20761

Closed
vszakats wants to merge 3 commits intocurl:masterfrom
vszakats:msvcold-snprintf
Closed

mprintf: use _snprintf() when compiled with VS2013 and older#20761
vszakats wants to merge 3 commits intocurl:masterfrom
vszakats:msvcold-snprintf

Conversation

@vszakats
Copy link
Copy Markdown
Member

@vszakats vszakats commented Feb 27, 2026

To support floats and doubles when using these old compilers.

Before this patch, these tests most likely failed with them:

FAIL 557: 'curl_mprintf() testing' printf, unittest
FAIL 566: 'HTTP GET with CURLINFO_CONTENT_LENGTH_DOWNLOAD and 0 bytes transfer' HTTP, HTTP GET
FAIL 599: 'HTTP GET with progress callback and redirects changing content sizes' HTTP, HTTP POST, chunked Transfer-Encoding
FAIL 1148: 'progress-bar' HTTP, progressbar

Also:

  • mention _snprintf() in the _CRT_SECURE_NO_WARNINGS comment.

Follow-up to 7de3551 #20218

@vszakats vszakats added Windows Windows-specific libcurl API labels Feb 27, 2026
@vszakats vszakats closed this in fa8bd1c Feb 27, 2026
@vszakats vszakats deleted the msvcold-snprintf branch February 27, 2026 14:58
vszakats added a commit that referenced this pull request Mar 2, 2026
…ows)

Make the helper use `vsnprintf()` internally on all supported Windows
toolchains (dropping `_snprintf()` and `snprintf()`), ensure to
nul-terminate. Omit the return value to avoid complexity.

Use the helper from `mprintf.c` / `out_double()`, from tests/server code
and the tests/server-specific build of `curlx_inet_ntop()`,
`curlx_strerror()` functions. In the single call (in tests) where the
returned length was used previously, determine it with `strlen()`.

Refs:
https://github.com/libssh2/libssh2/blob/libssh2-1.11.1/src/misc.c#L57-L79
https://learn.microsoft.com/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l
https://learn.microsoft.com/cpp/c-runtime-library/reference/vsnprintf-vsnprintf-vsnprintf-l-vsnwprintf-vsnwprintf-l

Assisted-by: Jay Satiro
Follow-up to fa8bd1c #20761
Follow-up to 8ab468c #15997

Closes #20765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libcurl API Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant