-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Closed
Labels
Description
I did this
3558e14 2017-05-29
When the undefined behavior sanitizer is enabled (CFLAGS and LDFLAGS -fsanitize=address,undefined -fno-sanitize-recover) test 557 will not complete due to undefined behavior of int left shift 1 << 31, refer to lib557.c:1620.
Output
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
=== Start of file curlverout.log
curl 7.54.1-DEV (x86_64-pc-linux-gnu) libcurl/7.54.1-DEV OpenSSL/1.0.2l zlib/1.2.8 nghttp2/1.23.0 librtmp/2.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: Debug TrackMemory IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy
=== End of file curlverout.log
=== Start of file stderr557
URL: nothing
lib557.c:1625:45: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
=== End of file stderr557
Solution
I think the most correct one would be use INT_MIN since afaics the purpose would be the same?
diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c
index ca3118a..8004548 100644
--- a/tests/libtest/lib557.c
+++ b/tests/libtest/lib557.c
@@ -1621,8 +1621,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