mirror of
https://github.com/curl/curl.git
synced 2026-08-25 10:43:34 +03:00
curlx: add local snprintf() helper that always nul-terminates (Windows)
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 tofa8bd1cc09#20761 Follow-up to8ab468c8aa#15997 Closes #20765
This commit is contained in:
parent
b83ade783d
commit
64f28b8f88
8 changed files with 76 additions and 20 deletions
|
|
@ -40,6 +40,7 @@ CURLX_C = \
|
|||
../../lib/curlx/inet_pton.c \
|
||||
../../lib/curlx/multibyte.c \
|
||||
../../lib/curlx/nonblock.c \
|
||||
../../lib/curlx/snprintf.c \
|
||||
../../lib/curlx/strcopy.c \
|
||||
../../lib/curlx/strerr.c \
|
||||
../../lib/curlx/strparse.c \
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ extern const struct entry_s s_entries[];
|
|||
|
||||
#include <curlx/curlx.h>
|
||||
|
||||
/* adjust for old MSVC */
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#ifdef _WIN32
|
||||
#include <curlx/snprintf.h>
|
||||
#define snprintf curlx_win32_snprintf
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
|
|||
|
|
@ -606,8 +606,9 @@ static int validate_access(struct testcase *test,
|
|||
|
||||
if(!strncmp("verifiedserver", filename, 14)) {
|
||||
char weare[128];
|
||||
size_t count = snprintf(weare, sizeof(weare), "WE ROOLZ: %ld\r\n",
|
||||
(long)our_getpid());
|
||||
size_t count;
|
||||
snprintf(weare, sizeof(weare), "WE ROOLZ: %ld\r\n", (long)our_getpid());
|
||||
count = strlen(weare);
|
||||
|
||||
logmsg("Are-we-friendly question received");
|
||||
test->buffer = curlx_strdup(weare);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue