[PATCH] D74666: Prevent gcc from issuing a warning upon coffnamecpy
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 16 13:03:52 PST 2020
serge-sans-paille updated this revision to Diff 244896.
serge-sans-paille added a comment.
I've manually checked the fact that out memory has been zeroed, and added an assert to make sure it remains so.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74666/new/
https://reviews.llvm.org/D74666
Files:
llvm/lib/Object/WindowsResource.cpp
Index: llvm/lib/Object/WindowsResource.cpp
===================================================================
--- llvm/lib/Object/WindowsResource.cpp
+++ llvm/lib/Object/WindowsResource.cpp
@@ -721,8 +721,10 @@
// it's okay to *not* copy the trailing zero.
static void coffnamecpy(char (&Dest)[COFF::NameSize], StringRef Src) {
assert(Src.size() <= COFF::NameSize &&
- "Src is not larger than COFF::NameSize");
- strncpy(Dest, Src.data(), (size_t)COFF::NameSize);
+ "Src is larger than COFF::NameSize");
+ assert((Src.size() == COFF::NameSize || Dest[Src.size()] == '\0') &&
+ "Dest not zeroed upon initialization");
+ memcpy(Dest, Src.data(), Src.size());
}
void WindowsResourceCOFFWriter::writeCOFFHeader(uint32_t TimeDateStamp) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74666.244896.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200216/4bdfe519/attachment.bin>
More information about the llvm-commits
mailing list