Skip to content

Commit 9ef60ff

Browse files
[llvm][utils] Improve the StringRef summary provider (#162298)
- check the length of data before casting as `char[N]` because the will cause lldb to allocate `N` bytes of memory. --------- Co-authored-by: Dave Lee <[email protected]>
1 parent 89b18f0 commit 9ef60ff

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

llvm/utils/lldbDataFormatters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ def StringRefSummaryProvider(valobj, internal_dict):
197197
return '""'
198198

199199
data = data_pointer.deref
200+
# StringRef may be uninitialized with length exceeding available memory,
201+
# potentially causing bad_alloc exceptions. Limit the length to max string summary setting.
202+
limit_obj = valobj.target.debugger.GetSetting("target.max-string-summary-length")
203+
if limit_obj:
204+
length = min(length, limit_obj.GetUnsignedIntegerValue())
200205
# Get a char[N] type, from the underlying char type.
201206
array_type = data.type.GetArrayType(length)
202207
# Cast the char* string data to a char[N] array.

0 commit comments

Comments
 (0)