[llvm-branch-commits] [llvm] 9a0900d - [NFC][AIX][XCOFF] Fix compile warning on strncpy
Yang Fan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 18 22:11:26 PST 2021
Author: Yang Fan
Date: 2021-01-19T14:07:11+08:00
New Revision: 9a0900dc4c6b3390fc886b7b556196da82ba1204
URL: https://github.com/llvm/llvm-project/commit/9a0900dc4c6b3390fc886b7b556196da82ba1204
DIFF: https://github.com/llvm/llvm-project/commit/9a0900dc4c6b3390fc886b7b556196da82ba1204.diff
LOG: [NFC][AIX][XCOFF] Fix compile warning on strncpy
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));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D94872
Added:
Modified:
llvm/lib/MC/XCOFFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index d6cee3bb59bb..031eceaadf06 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -138,12 +138,13 @@ struct Section {
Group->clear();
}
- Section(const char *N, XCOFF::SectionTypeFlags Flags, bool IsVirtual,
+ Section(StringRef N, XCOFF::SectionTypeFlags Flags, bool IsVirtual,
CsectGroups Groups)
- : Address(0), Size(0), FileOffsetToData(0), FileOffsetToRelocations(0),
- RelocationCount(0), Flags(Flags), Index(UninitializedIndex),
- IsVirtual(IsVirtual), Groups(Groups) {
- strncpy(Name, N, XCOFF::NameSize);
+ : Name(), Address(0), Size(0), FileOffsetToData(0),
+ FileOffsetToRelocations(0), RelocationCount(0), Flags(Flags),
+ Index(UninitializedIndex), IsVirtual(IsVirtual), Groups(Groups) {
+ assert(N.size() <= XCOFF::NameSize && "section name too long");
+ memcpy(Name, N.data(), N.size());
}
};
More information about the llvm-branch-commits
mailing list