Skip to content

Commit 767ce07

Browse files
Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). (#71559)
I received a couple of nullptr-deref crash reports with no line numbers in this function. The way the function was written it was a bit diffucult to keep track of when result_sp could be null, so this patch simplifies the function to make it more obvious when a nullptr can be contained in the variable.
1 parent 5ef4467 commit 767ce07

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

lldb/source/Core/ValueObject.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,34 +2594,30 @@ ValueObjectSP ValueObject::CreateConstantValue(ConstString name) {
25942594

25952595
ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable(
25962596
lldb::DynamicValueType dynValue, bool synthValue) {
2597-
ValueObjectSP result_sp(GetSP());
2598-
2597+
ValueObjectSP result_sp;
25992598
switch (dynValue) {
26002599
case lldb::eDynamicCanRunTarget:
26012600
case lldb::eDynamicDontRunTarget: {
2602-
if (!result_sp->IsDynamic()) {
2603-
if (result_sp->GetDynamicValue(dynValue))
2604-
result_sp = result_sp->GetDynamicValue(dynValue);
2605-
}
2601+
if (!IsDynamic())
2602+
result_sp = GetDynamicValue(dynValue);
26062603
} break;
26072604
case lldb::eNoDynamicValues: {
2608-
if (result_sp->IsDynamic()) {
2609-
if (result_sp->GetStaticValue())
2610-
result_sp = result_sp->GetStaticValue();
2611-
}
2605+
if (IsDynamic())
2606+
result_sp = GetStaticValue();
26122607
} break;
26132608
}
2609+
if (!result_sp)
2610+
result_sp = GetSP();
2611+
assert(result_sp);
26142612

2615-
if (synthValue) {
2616-
if (!result_sp->IsSynthetic()) {
2617-
if (result_sp->GetSyntheticValue())
2618-
result_sp = result_sp->GetSyntheticValue();
2619-
}
2620-
} else {
2621-
if (result_sp->IsSynthetic()) {
2622-
if (result_sp->GetNonSyntheticValue())
2623-
result_sp = result_sp->GetNonSyntheticValue();
2624-
}
2613+
bool is_synthetic = result_sp->IsSynthetic();
2614+
if (synthValue && !is_synthetic) {
2615+
if (auto synth_sp = result_sp->GetSyntheticValue())
2616+
return synth_sp;
2617+
}
2618+
if (!synthValue && is_synthetic) {
2619+
if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
2620+
return non_synth_sp;
26252621
}
26262622

26272623
return result_sp;

0 commit comments

Comments
 (0)