From bb3609e49d806904c80a6a6047e83ed5a65b0f24 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Wed, 6 Feb 2019 08:44:13 +0000 Subject: Fix strlen() of unbound array undefined behavior LLDB testsuite fails when built by GCC8 on: LLDB :: SymbolFile/DWARF/find-basic-namespace.cpp This is because this code in LLDB codebase has undefined behavior: #include #include // lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1731 static struct section_64 { char sectname[16]; char segname[16]; } sect64 = { {'_','_','a','p','p','l','e','_','n','a','m','e','s','p','a','c'}, "__DWARF" }; int main() { return std::min(strlen(sect64.sectname), sizeof(sect64.sectname)); } It has been discussed as a (false) bugreport to GCC: wrong-code: LLDB testcase fails: SymbolFile/DWARF/find-basic-namespace.cpp https://bugzilla.redhat.com/show_bug.cgi?id=1672436 Differential Revision: https://reviews.llvm.org/D57781 llvm-svn: 353280 --- lldb/source/Utility/ConstString.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lldb/source/Utility/ConstString.cpp') diff --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp index c12e930303d..7ab98ef5ce7 100644 --- a/lldb/source/Utility/ConstString.cpp +++ b/lldb/source/Utility/ConstString.cpp @@ -143,7 +143,7 @@ public: const char *GetConstTrimmedCStringWithLength(const char *cstr, size_t cstr_len) { if (cstr != nullptr) { - const size_t trimmed_len = std::min(strlen(cstr), cstr_len); + const size_t trimmed_len = strnlen(cstr, cstr_len); return GetConstCStringWithLength(cstr, trimmed_len); } return nullptr; -- cgit v1.2.3