Title: [231661] trunk
Revision
231661
Author
[email protected]
Date
2018-05-10 14:46:52 -0700 (Thu, 10 May 2018)

Log Message

Fix some -Wstring-op-truncation warnings
https://bugs.webkit.org/show_bug.cgi?id=185496

Reviewed by Alex Christensen.

Source/ThirdParty:

Disable this warning when building gtest.

* gtest/CMakeLists.txt:

Tools:

We have an off-by-one in the use of strncpy. The strings would not be null-terminated if
the input was too long. Ensure the buffers are zero-initialized so we don't need to manually
set the last bucket to NUL.

* TestWebKitAPI/Tests/WTF/AtomicString.cpp:
(TestWebKitAPI::testAtomicStringNumber):
* TestWebKitAPI/Tests/WTF/WTFString.cpp:
(TestWebKitAPI::testStringNumberFixedPrecision):
(TestWebKitAPI::testStringNumberFixedWidth):
(TestWebKitAPI::testStringNumber):

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ChangeLog (231660 => 231661)


--- trunk/Source/ThirdParty/ChangeLog	2018-05-10 21:31:49 UTC (rev 231660)
+++ trunk/Source/ThirdParty/ChangeLog	2018-05-10 21:46:52 UTC (rev 231661)
@@ -1,3 +1,14 @@
+2018-05-10  Michael Catanzaro  <[email protected]>
+
+        Fix some -Wstring-op-truncation warnings
+        https://bugs.webkit.org/show_bug.cgi?id=185496
+
+        Reviewed by Alex Christensen.
+
+        Disable this warning when building gtest.
+
+        * gtest/CMakeLists.txt:
+
 2018-05-09  Michael Catanzaro  <[email protected]>
 
         [WPE] Build cleanly with GCC 8 and ICU 60

Modified: trunk/Source/ThirdParty/gtest/CMakeLists.txt (231660 => 231661)


--- trunk/Source/ThirdParty/gtest/CMakeLists.txt	2018-05-10 21:31:49 UTC (rev 231660)
+++ trunk/Source/ThirdParty/gtest/CMakeLists.txt	2018-05-10 21:46:52 UTC (rev 231661)
@@ -35,6 +35,7 @@
 add_definitions(-DGTEST_HAS_RTTI=0)
 
 WEBKIT_ADD_TARGET_CXX_FLAGS(gtest -Wno-undef
+                                  -Wno-stringop-truncation
                                   -Wno-suggest-attribute=format)
 
 # FIXME: This works around compatibility problems in the old version of the third-pary

Modified: trunk/Tools/ChangeLog (231660 => 231661)


--- trunk/Tools/ChangeLog	2018-05-10 21:31:49 UTC (rev 231660)
+++ trunk/Tools/ChangeLog	2018-05-10 21:46:52 UTC (rev 231661)
@@ -1,3 +1,21 @@
+2018-05-10  Michael Catanzaro  <[email protected]>
+
+        Fix some -Wstring-op-truncation warnings
+        https://bugs.webkit.org/show_bug.cgi?id=185496
+
+        Reviewed by Alex Christensen.
+
+        We have an off-by-one in the use of strncpy. The strings would not be null-terminated if
+        the input was too long. Ensure the buffers are zero-initialized so we don't need to manually
+        set the last bucket to NUL.
+
+        * TestWebKitAPI/Tests/WTF/AtomicString.cpp:
+        (TestWebKitAPI::testAtomicStringNumber):
+        * TestWebKitAPI/Tests/WTF/WTFString.cpp:
+        (TestWebKitAPI::testStringNumberFixedPrecision):
+        (TestWebKitAPI::testStringNumberFixedWidth):
+        (TestWebKitAPI::testStringNumber):
+
 2018-05-10  Fujii Hironori  <[email protected]>
 
         [Win][MiniBrowser] Add a separate WndProc for the layered window

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp (231660 => 231661)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp	2018-05-10 21:31:49 UTC (rev 231660)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp	2018-05-10 21:46:52 UTC (rev 231661)
@@ -63,8 +63,8 @@
 
 static inline const char* testAtomicStringNumber(double number)
 {
-    static char testBuffer[100];
-    std::strncpy(testBuffer, AtomicString::number(number).string().utf8().data(), 100);
+    static char testBuffer[100] = { };
+    std::strncpy(testBuffer, AtomicString::number(number).string().utf8().data(), 99);
     return testBuffer;
 }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp (231660 => 231661)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2018-05-10 21:31:49 UTC (rev 231660)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2018-05-10 21:46:52 UTC (rev 231661)
@@ -67,8 +67,8 @@
 
 static inline const char* testStringNumberFixedPrecision(double number)
 {
-    static char testBuffer[100];
-    std::strncpy(testBuffer, String::number(number).utf8().data(), 100);
+    static char testBuffer[100] = { };
+    std::strncpy(testBuffer, String::number(number).utf8().data(), 99);
     return testBuffer;
 }
 
@@ -116,8 +116,8 @@
 
 static inline const char* testStringNumberFixedWidth(double number)
 {
-    static char testBuffer[100];
-    std::strncpy(testBuffer, String::numberToStringFixedWidth(number, 6).utf8().data(), 100);
+    static char testBuffer[100] = { };
+    std::strncpy(testBuffer, String::numberToStringFixedWidth(number, 6).utf8().data(), 99);
     return testBuffer;
 }
 
@@ -165,8 +165,8 @@
 
 static inline const char* testStringNumber(double number)
 {
-    static char testBuffer[100];
-    std::strncpy(testBuffer, String::numberToStringECMAScript(number).utf8().data(), 100);
+    static char testBuffer[100] = { };
+    std::strncpy(testBuffer, String::numberToStringECMAScript(number).utf8().data(), 99);
     return testBuffer;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to