[PATCH] D94872: [NFC][AIX][XCOFF] Fix compile warning on strncpy

Yang Fan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 16 20:40:45 PST 2021


nullptr.cpp created this revision.
nullptr.cpp added reviewers: DiggerLin, daltenty.
Herald added subscribers: pengfei, hiraditya.
nullptr.cpp requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

GCC warning:

  In file included from /usr/include/string.h:495,
                   from /usr/include/c++/9/cstring:42,
                   from /llvm-project/llvm/include/llvm/ADT/Hashing.h:53,
                   from /llvm-project/llvm/include/llvm/ADT/ArrayRef.h:12,
                   from /llvm-project/llvm/include/llvm/MC/MCAsmBackend.h:12,
                   from /llvm-project/llvm/lib/MC/XCOFFObjectWriter.cpp:14:
  In function ‘char* strncpy(char*, const char*, size_t)’,
      inlined from ‘{anonymous}::Section::Section(const char*, llvm::XCOFF::SectionTypeFlags, bool, {anonymous}::CsectGroups)’ at /llvm-project/llvm/lib/MC/XCOFFObjectWriter.cpp:146:12:
  /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 8 equals destination size [-Wstringop-truncation]
    106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
        |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it in the same way as D71119 <https://reviews.llvm.org/D71119>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94872

Files:
  llvm/lib/MC/XCOFFObjectWriter.cpp


Index: llvm/lib/MC/XCOFFObjectWriter.cpp
===================================================================
--- llvm/lib/MC/XCOFFObjectWriter.cpp
+++ llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -99,7 +99,7 @@
 // stored separately, e.g. the .data section containing read-write, descriptor,
 // TOCBase and TOC-entry csects.
 struct Section {
-  char Name[XCOFF::NameSize];
+  char Name[XCOFF::NameSize + 1];
   // The physical/virtual address of the section. For an object file
   // these values are equivalent.
   uint32_t Address;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94872.317207.patch
Type: text/x-patch
Size: 528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210117/2fcd446d/attachment.bin>


More information about the llvm-commits mailing list