Skip to content

Commit a3dac2e

Browse files
committed
Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). (llvm#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. (cherry picked from commit 767ce07)
1 parent 0bbc472 commit a3dac2e

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
@@ -2716,34 +2716,30 @@ ValueObjectSP ValueObject::CreateConstantValue(ConstString name) {
27162716

27172717
ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable(
27182718
lldb::DynamicValueType dynValue, bool synthValue) {
2719-
ValueObjectSP result_sp(GetSP());
2720-
2719+
ValueObjectSP result_sp;
27212720
switch (dynValue) {
27222721
case lldb::eDynamicCanRunTarget:
27232722
case lldb::eDynamicDontRunTarget: {
2724-
if (!result_sp->IsDynamic()) {
2725-
if (result_sp->GetDynamicValue(dynValue))
2726-
result_sp = result_sp->GetDynamicValue(dynValue);
2727-
}
2723+
if (!IsDynamic())
2724+
result_sp = GetDynamicValue(dynValue);
27282725
} break;
27292726
case lldb::eNoDynamicValues: {
2730-
if (result_sp->IsDynamic()) {
2731-
if (result_sp->GetStaticValue())
2732-
result_sp = result_sp->GetStaticValue();
2733-
}
2727+
if (IsDynamic())
2728+
result_sp = GetStaticValue();
27342729
} break;
27352730
}
2731+
if (!result_sp)
2732+
result_sp = GetSP();
2733+
assert(result_sp);
27362734

2737-
if (synthValue) {
2738-
if (!result_sp->IsSynthetic()) {
2739-
if (result_sp->GetSyntheticValue())
2740-
result_sp = result_sp->GetSyntheticValue();
2741-
}
2742-
} else {
2743-
if (result_sp->IsSynthetic()) {
2744-
if (result_sp->GetNonSyntheticValue())
2745-
result_sp = result_sp->GetNonSyntheticValue();
2746-
}
2735+
bool is_synthetic = result_sp->IsSynthetic();
2736+
if (synthValue && !is_synthetic) {
2737+
if (auto synth_sp = result_sp->GetSyntheticValue())
2738+
return synth_sp;
2739+
}
2740+
if (!synthValue && is_synthetic) {
2741+
if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
2742+
return non_synth_sp;
27472743
}
27482744

27492745
return result_sp;

0 commit comments

Comments
 (0)