https://github.com/adrian-prantl created https://github.com/llvm/llvm-project/pull/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. >From 5181bfab3fad13f6fce1425db5a93e2ab6e1fcd5 Mon Sep 17 00:00:00 2001 From: Adrian Prantl <apra...@apple.com> Date: Tue, 7 Nov 2023 08:25:34 -0800 Subject: [PATCH] Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). 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. --- lldb/source/Core/ValueObject.cpp | 36 ++++++++++++++------------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index bdb1bef633d8fb1..a7f7ee64282d891 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -2594,34 +2594,30 @@ ValueObjectSP ValueObject::CreateConstantValue(ConstString name) { ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable( lldb::DynamicValueType dynValue, bool synthValue) { - ValueObjectSP result_sp(GetSP()); - + ValueObjectSP result_sp; switch (dynValue) { case lldb::eDynamicCanRunTarget: case lldb::eDynamicDontRunTarget: { - if (!result_sp->IsDynamic()) { - if (result_sp->GetDynamicValue(dynValue)) - result_sp = result_sp->GetDynamicValue(dynValue); - } + if (!IsDynamic()) + result_sp = GetDynamicValue(dynValue); } break; case lldb::eNoDynamicValues: { - if (result_sp->IsDynamic()) { - if (result_sp->GetStaticValue()) - result_sp = result_sp->GetStaticValue(); - } + if (IsDynamic()) + result_sp = GetStaticValue(); } break; } + if (!result_sp) + result_sp = GetSP(); + assert(result_sp); - if (synthValue) { - if (!result_sp->IsSynthetic()) { - if (result_sp->GetSyntheticValue()) - result_sp = result_sp->GetSyntheticValue(); - } - } else { - if (result_sp->IsSynthetic()) { - if (result_sp->GetNonSyntheticValue()) - result_sp = result_sp->GetNonSyntheticValue(); - } + bool is_synthetic = result_sp->IsSynthetic(); + if (synthValue && !is_synthetic) { + if (auto synth_sp = result_sp->GetSyntheticValue()) + return synth_sp; + } + if (!synthValue && is_synthetic) { + if (auto non_synth_sp = result_sp->GetNonSyntheticValue()) + return non_synth_sp; } return result_sp; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits