[Lldb-commits] [lldb] 21ab32e - [lldb][LibCxx] Move incorrect nullptr check (#96635)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 25 11:05:19 PDT 2024
Author: Michael Buch
Date: 2024-06-25T19:05:16+01:00
New Revision: 21ab32e1c144b42458b7b3181e84bfb45aadcc54
URL: https://github.com/llvm/llvm-project/commit/21ab32e1c144b42458b7b3181e84bfb45aadcc54
DIFF: https://github.com/llvm/llvm-project/commit/21ab32e1c144b42458b7b3181e84bfb45aadcc54.diff
LOG: [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`.
Added:
Modified:
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Removed:
################################################################################
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