This is an archive of the discontinued LLVM Phabricator instance.

Avoid using a variable-sized array for a tiny allocation.
ClosedPublic

Authored by saugustine on Mar 15 2022, 12:57 PM.

Diff Detail

Event Timeline

saugustine created this revision.Mar 15 2022, 12:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 12:57 PM
saugustine requested review of this revision.Mar 15 2022, 12:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 12:57 PM
This revision was not accepted when it landed; it landed in state Needs Review.Mar 15 2022, 1:04 PM
This revision was automatically updated to reflect the committed changes.
JDevlieghere added inline comments.Mar 15 2022, 1:59 PM
lldb/source/Expression/DWARFExpression.cpp
1309

Why size and not 8?

saugustine added inline comments.Mar 15 2022, 2:05 PM
lldb/source/Expression/DWARFExpression.cpp
1309

Because that preserves the semantics of the original code. The original code allocates anywhere from 1 to 8 bytes, based on size `uint8_t addr_bytes[size];`. Then reads that amount from memory (line 1303 - 1304), and then passes the size of the allocation on this line (via `sizeof(addr_bytes)`).

Always passing eight here would be wrong, because the size of the pointer could have been anywhere from 1 to 8.

Not also how line 1309 read size-bytes read into addr_bytes.