[PATCH] D74666: Prevent gcc from issuing a warning upon coffnamecpy

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 00:04:38 PST 2020


serge-sans-paille created this revision.
serge-sans-paille added reviewers: thakis, rnk.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

This is a follow up to d1262a6e9, more explicit to cope with GCC smartness.

The intent is also more explicit now. Otherwise GCC 9.2 inlines coffnamecpy and trigger a (rightful) warning.


Repository:
  rG LLVM Github Monorepo

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
@@ -722,7 +722,9 @@
 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);
+  memcpy(Dest, Src.data(), Src.size());
+  if(Src.size() < COFF::NameSize)
+    Dest[Src.size()] = '\0';
 }
 
 void WindowsResourceCOFFWriter::writeCOFFHeader(uint32_t TimeDateStamp) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74666.244819.patch
Type: text/x-patch
Size: 617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200215/c2c59126/attachment.bin>


More information about the llvm-commits mailing list