Page MenuHomePhabricator

Fix strlen() of unbound array undefined behavior

Authored by jankratochvil on Feb 5 2019, 1:21 PM.



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 <algorithm>
#include <string.h>
// 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<size_t>(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

I will check it in if there are no comments as it looks obvious enough to me.

Diff Detail


Event Timeline

jankratochvil created this revision.Feb 5 2019, 1:21 PM
aprantl accepted this revision.Feb 5 2019, 1:38 PM


This revision is now accepted and ready to land.Feb 5 2019, 1:38 PM
labath accepted this revision.Feb 5 2019, 1:46 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2019, 12:44 AM