Bug 185496 - Fix some -Wstring-op-truncation warnings
Summary: Fix some -Wstring-op-truncation warnings
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-05-09 16:39 PDT by Michael Catanzaro
Modified: 2018-05-13 07:32 PDT (History)
6 users (show)

See Also:


Attachments
Patch (4.49 KB, patch)
2018-05-09 20:02 PDT, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2018-05-09 16:39:55 PDT
testAtomicStringNumber may not be null-terminated. Caught by -Wstringop-truncation:

../../Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp:67:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
Comment 1 Michael Catanzaro 2018-05-09 16:52:09 PDT
Also, related:

[415/2047] Building CXX object Tools/TestWebKitAPI/CMakeFiles/TestWTF.dir/Tests/WTF/WTFString.cpp.o
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp: In function ‘const char* TestWebKitAPI::testStringNumber(double)’:
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:169:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
     std::strncpy(testBuffer, String::numberToStringECMAScript(number).utf8().data(), 100);
     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:169:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp: In function ‘const char* TestWebKitAPI::testStringNumberFixedWidth(double)’:
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:120:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
     std::strncpy(testBuffer, String::numberToStringFixedWidth(number, 6).utf8().data(), 100);
     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:120:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp: In function ‘const char* TestWebKitAPI::testStringNumberFixedPrecision(double)’:
../../Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:71:17: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 100 equals destination size [-Wstringop-truncation]
     std::strncpy(testBuffer, String::number(number).utf8().data(), 100);
     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 2 Michael Catanzaro 2018-05-09 20:02:16 PDT
Created attachment 340064 [details]
Patch
Comment 3 WebKit Commit Bot 2018-05-10 14:46:57 PDT
Comment on attachment 340064 [details]
Patch

Clearing flags on attachment: 340064

Committed r231661: <https://trac.webkit.org/changeset/231661>
Comment 4 WebKit Commit Bot 2018-05-10 14:46:58 PDT
All reviewed patches have been landed.  Closing bug.
Comment 5 Radar WebKit Bug Importer 2018-05-10 14:47:41 PDT
<rdar://problem/40142604>
Comment 6 Darin Adler 2018-05-12 21:41:56 PDT
Thanks for fixing this. For the record, changing the 100 to 99 was necessary, but adding the "= { }" was not since these are globals and initialized to zero in any case.
Comment 7 Michael Catanzaro 2018-05-13 07:32:59 PDT
(In reply to Darin Adler from comment #6)
> Thanks for fixing this. For the record, changing the 100 to 99 was
> necessary, but adding the "= { }" was not since these are globals and
> initialized to zero in any case.

Good point, you're right! I overlooked the static keyword.