Skip to content

Commit

Permalink
Merge r231661 - Fix some -Wstring-op-truncation warnings
Browse files Browse the repository at this point in the history
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):
  • Loading branch information
mcatanzaro committed May 11, 2018
1 parent 843dfaf commit a6c10ee
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
11 changes: 11 additions & 0 deletions Source/ThirdParty/ChangeLog
@@ -1,3 +1,14 @@
2018-05-10 Michael Catanzaro <mcatanzaro@igalia.com>

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-10 Michael Catanzaro <mcatanzaro@igalia.com>

Unreviewed, silence a couple more build warnings on the stable branch
Expand Down
1 change: 1 addition & 0 deletions Source/ThirdParty/gtest/CMakeLists.txt
Expand Up @@ -35,6 +35,7 @@ include_directories(${GTEST_INCLUDE_DIRECTORIES})
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
Expand Down
18 changes: 18 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,21 @@
2018-05-10 Michael Catanzaro <mcatanzaro@igalia.com>

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 Michael Catanzaro <mcatanzaro@igalia.com>

[WPE][STABLE] Remove unusable JavaScript APIs
Expand Down
4 changes: 2 additions & 2 deletions Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp
Expand Up @@ -63,8 +63,8 @@ TEST(WTF, AtomicStringExistingHash)

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;
}

Expand Down
12 changes: 6 additions & 6 deletions Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp
Expand Up @@ -67,8 +67,8 @@ TEST(WTF, StringASCII)

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;
}

Expand Down Expand Up @@ -116,8 +116,8 @@ TEST(WTF, StringNumberFixedPrecision)

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;
}

Expand Down Expand Up @@ -165,8 +165,8 @@ TEST(WTF, StringNumberFixedWidth)

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;
}

Expand Down

0 comments on commit a6c10ee

Please sign in to comment.