[Lldb-commits] [lldb] [lldb][LibCxx] Move incorrect nullptr check (PR #96635)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 25 06:28:16 PDT 2024


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/96635

Found this 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`.

>From 87edb6b9ba8b48e1bcddd2d73314cdb8f4e0a73b Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 25 Jun 2024 14:25:07 +0100
Subject: [PATCH] [lldb][LibCxx] Move incorrect nullptr check

Found this 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`.
---
 lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index b0e6fb7d6f5af..0f9f93b727ce8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -808,6 +808,9 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {
       size = (layout == StringLayout::DSC) ? size_mode_value
                                            : ((size_mode_value >> 1) % 256);
 
+    if (!location_sp)
+      return {};
+
     // When the small-string optimization takes place, the data must fit in the
     // inline string buffer (23 bytes on x86_64/Darwin). If it doesn't, it's
     // likely that the string isn't initialized and we're reading garbage.
@@ -815,7 +818,7 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {
     const std::optional<uint64_t> max_bytes =
         location_sp->GetCompilerType().GetByteSize(
             exe_ctx.GetBestExecutionContextScope());
-    if (!max_bytes || size > *max_bytes || !location_sp)
+    if (!max_bytes || size > *max_bytes)
       return {};
 
     return std::make_pair(size, location_sp);



More information about the lldb-commits mailing list