Skip to content

Commit 21ab32e

Browse files
authored
[lldb][LibCxx] Move incorrect nullptr check (#96635)
Found while skimming this code. Don't have a reproducible test case for this but the nullptr check should clearly occur before we try to dereference `location_sp`.
1 parent a086933 commit 21ab32e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,17 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {
808808
size = (layout == StringLayout::DSC) ? size_mode_value
809809
: ((size_mode_value >> 1) % 256);
810810

811+
if (!location_sp)
812+
return {};
813+
811814
// When the small-string optimization takes place, the data must fit in the
812815
// inline string buffer (23 bytes on x86_64/Darwin). If it doesn't, it's
813816
// likely that the string isn't initialized and we're reading garbage.
814817
ExecutionContext exe_ctx(location_sp->GetExecutionContextRef());
815818
const std::optional<uint64_t> max_bytes =
816819
location_sp->GetCompilerType().GetByteSize(
817820
exe_ctx.GetBestExecutionContextScope());
818-
if (!max_bytes || size > *max_bytes || !location_sp)
821+
if (!max_bytes || size > *max_bytes)
819822
return {};
820823

821824
return std::make_pair(size, location_sp);

0 commit comments

Comments
 (0)