[Lldb-commits] [PATCH] D121732: Avoid using a variable-sized array for a tiny allocation.

Sterling Augustine via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 15 14:05:45 PDT 2022


saugustine added inline comments.


================
Comment at: lldb/source/Expression/DWARFExpression.cpp:1309
             stack.back().GetScalar() = DerefSizeExtractDataHelper(
-                addr_bytes, sizeof(addr_bytes), objfile->GetByteOrder(), size);
+                addr_bytes, size, objfile->GetByteOrder(), size);
             stack.back().ClearContext();
----------------
JDevlieghere wrote:
> Why size and not `8`?
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121732/new/

https://reviews.llvm.org/D121732



More information about the lldb-commits mailing list