]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test557: fix ubsan runtime error due to int left shift
authorJay Satiro <raysatiro@yahoo.com>
Mon, 29 May 2017 22:04:53 +0000 (18:04 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Mon, 29 May 2017 22:04:53 +0000 (18:04 -0400)
- Test curl_msnprintf negative int width arg using INT_MIN instead of
  1 << 31 which is undefined behavior.

Closes https://github.com/curl/curl/issues/1516

tests/libtest/lib557.c

index ca3118aec296116ab0fd5c892a14cb800fe6b313..4a598f22dce06cd2b5f041b5f5e8b51ba1f1c84a 100644 (file)
 
 #include "test.h"
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
 #ifdef HAVE_LOCALE_H
 #  include <locale.h> /* for setlocale() */
 #endif
@@ -1621,8 +1625,8 @@ static int test_float_formatting(void)
                  123456789123456789123456789.2987654);
   errors += strlen_check(buf, 325);
 
-  /* 1<<31 turns negative (-2147483648) when used signed */
-  curl_msnprintf(buf, sizeof(buf), "%*f", (1<<31), 9.1);
+  /* check negative when used signed */
+  curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
   errors += string_check(buf, "9.100000");
 
   /* curl_msnprintf() limits a single float output to 325 bytes maximum