]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
mprintf: use `_snprintf()` when compiled with VS2013 and older
authorViktor Szakats <commit@vsz.me>
Thu, 26 Feb 2026 23:38:07 +0000 (00:38 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 27 Feb 2026 14:57:48 +0000 (15:57 +0100)
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 7de35515d90d364e851cdde712062b942d6bf36a #20218

Closes #20761

lib/curl_setup.h
lib/mprintf.c

index b7c030c00656d79a613eef6fead9f37db286b2a9..4629f79fb94f11d048c0a9201fe2ec41404dbc45 100644 (file)
@@ -90,7 +90,7 @@
 /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
 #pragma warning(disable:4127)
 #ifndef _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_WARNINGS  /* for getenv(), tests: sscanf() */
+#define _CRT_SECURE_NO_WARNINGS  /* for _snprintf(), getenv(), sscanf() */
 #endif
 #endif /* _MSC_VER */
 
index 10cede837c33164381a43f0ddc498c4021db6899..b00f16e34bc792fa909e09b382cfc1289dad2e33 100644 (file)
@@ -688,6 +688,9 @@ static bool out_double(void *userp,
      buffer if it reaches the max size so we do that here. */
   work[BUFFSIZE - 1] = 0;
 #endif
+#elif defined(_MSC_VER) && (_MSC_VER < 1900)
+  _snprintf(work, BUFFSIZE, formatbuf, dnum);
+  work[BUFFSIZE - 1] = 0;
 #else
   /* float and double outputs do not work without snprintf support */
   work[0] = 0;