Skip to content

Commit 8965dd4

Browse files
authored
[lldb] Handle a byte size of zero in CompilerType::GetValueAsScalar (#123107)
A bit or byte size of 0 is not a bug. It can legitimately (and frequently) happen in Swift and C, just not in C++. However, it doesn't make sense to read a scalar of zero bytes. Currently, when this happens, we trigger an `lldb_assert` in the data extractor and return 0, which isn't accurate. I have a bunch of reports of the assert triggering, but nobody has been able to provide me with a reproducer that I can turn into a test and I wasn't able to concoct a test case by reverse-engineering the code. rdar://141630334
1 parent 60e4d24 commit 8965dd4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lldb/source/Symbol/CompilerType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,11 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
11051105
return false;
11061106

11071107
std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
1108-
if (!byte_size)
1108+
// A bit or byte size of 0 is not a bug, but it doesn't make sense to read a
1109+
// scalar of zero size.
1110+
if (!byte_size || *byte_size == 0)
11091111
return false;
1112+
11101113
lldb::offset_t offset = data_byte_offset;
11111114
switch (encoding) {
11121115
case lldb::eEncodingInvalid:

0 commit comments

Comments
 (0)