summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/mprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libcurl/src/mprintf.c')
-rw-r--r--libs/libcurl/src/mprintf.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/libs/libcurl/src/mprintf.c b/libs/libcurl/src/mprintf.c
index 5722c6d838..572ba1980d 100644
--- a/libs/libcurl/src/mprintf.c
+++ b/libs/libcurl/src/mprintf.c
@@ -37,14 +37,12 @@
#ifdef HAVE_LONGLONG
# define LONG_LONG_TYPE long long
# define HAVE_LONG_LONG_TYPE
+#elif defined(_MSC_VER)
+# define LONG_LONG_TYPE __int64
+# define HAVE_LONG_LONG_TYPE
#else
-# if defined(_MSC_VER) && (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
-# define LONG_LONG_TYPE __int64
-# define HAVE_LONG_LONG_TYPE
-# else
-# undef LONG_LONG_TYPE
-# undef HAVE_LONG_LONG_TYPE
-# endif
+# undef LONG_LONG_TYPE
+# undef HAVE_LONG_LONG_TYPE
#endif
/*
@@ -680,12 +678,12 @@ static int formatf(
struct outsegment output[MAX_SEGMENTS];
struct va_input input[MAX_PARAMETERS];
- char work[BUFFSIZE];
+ char work[BUFFSIZE + 2];
/* 'workend' points to the final buffer byte position, but with an extra
byte as margin to avoid the (FALSE?) warning Coverity gives us
otherwise */
- char *workend = &work[sizeof(work) - 2];
+ char *workend = &work[BUFFSIZE - 2];
/* Parse the format string */
if(parsefmt(format, output, input, &ocount, &icount, ap_save))
@@ -968,8 +966,8 @@ number:
if(width >= 0) {
size_t dlen;
- if(width >= (int)sizeof(work))
- width = sizeof(work)-1;
+ if(width >= BUFFSIZE)
+ width = BUFFSIZE - 1;
/* RECURSIVE USAGE */
dlen = (size_t)curl_msnprintf(fptr, left, "%d", width);
fptr += dlen;
@@ -978,17 +976,19 @@ number:
if(prec >= 0) {
/* for each digit in the integer part, we can have one less
precision */
- size_t maxprec = sizeof(work) - 2;
+ int maxprec = BUFFSIZE - 1;
double val = iptr->val.dnum;
+ if(prec > maxprec)
+ prec = maxprec - 1;
if(width > 0 && prec <= width)
- maxprec -= (size_t)width;
+ maxprec -= width;
while(val >= 10.0) {
val /= 10;
maxprec--;
}
- if(prec > (int)maxprec)
- prec = (int)maxprec-1;
+ if(prec > maxprec)
+ prec = maxprec - 1;
if(prec < 0)
prec = 0;
/* RECURSIVE USAGE */
@@ -1014,14 +1014,19 @@ number:
/* NOTE NOTE NOTE!! Not all sprintf implementations return number of
output characters */
#ifdef HAVE_SNPRINTF
- (snprintf)(work, sizeof(work), formatbuf, iptr->val.dnum);
+ (snprintf)(work, BUFFSIZE, formatbuf, iptr->val.dnum); /* NOLINT */
+#ifdef _WIN32
+ /* Old versions of the Windows CRT do not terminate the snprintf output
+ buffer if it reaches the max size so we do that here. */
+ work[BUFFSIZE - 1] = 0;
+#endif
#else
(sprintf)(work, formatbuf, iptr->val.dnum);
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
- DEBUGASSERT(strlen(work) <= sizeof(work));
+ DEBUGASSERT(strlen(work) < BUFFSIZE);
for(fptr = work; *fptr; fptr++)
OUTCHAR(*fptr);
break;