[llvm] 498a613 - Prevent gcc from issuing a warning upon coffnamecpy
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 07:14:29 PST 2020
Author: serge-sans-paille
Date: 2020-02-18T16:13:59+01:00
New Revision: 498a6136a271bfb95bcd9488d1036e57a5e0fae0
URL: https://github.com/llvm/llvm-project/commit/498a6136a271bfb95bcd9488d1036e57a5e0fae0
DIFF: https://github.com/llvm/llvm-project/commit/498a6136a271bfb95bcd9488d1036e57a5e0fae0.diff
LOG: Prevent gcc from issuing a warning upon coffnamecpy
This is a follow up to d1262a6e9, more explicit to cope with GCC smartness.
Differential Revision: https://reviews.llvm.org/D74666
Added:
Modified:
llvm/lib/Object/WindowsResource.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/WindowsResource.cpp b/llvm/lib/Object/WindowsResource.cpp
index 0cf9da43ae29..2a69c6c46b59 100644
--- a/llvm/lib/Object/WindowsResource.cpp
+++ b/llvm/lib/Object/WindowsResource.cpp
@@ -721,8 +721,10 @@ WindowsResourceCOFFWriter::write(uint32_t TimeDateStamp) {
// 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) {
More information about the llvm-commits
mailing list