[Lldb-commits] [lldb] f451d27 - [lldb] Assert on invalid default {S, U}Int64 (NFC) (#126590)

via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 10 15:10:24 PST 2025


Author: Jonas Devlieghere
Date: 2025-02-10T15:10:21-08:00
New Revision: f451d27b387cdff14f0f45f1b3314090a5008e0c

URL: https://github.com/llvm/llvm-project/commit/f451d27b387cdff14f0f45f1b3314090a5008e0c
DIFF: https://github.com/llvm/llvm-project/commit/f451d27b387cdff14f0f45f1b3314090a5008e0c.diff

LOG: [lldb] Assert on invalid default {S,U}Int64 (NFC) (#126590)

Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/OptionValueSInt64.h
    lldb/include/lldb/Interpreter/OptionValueUInt64.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/OptionValueSInt64.h b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
index 3cf41d38c0ef0c5..f7e72684e4102f9 100644
--- a/lldb/include/lldb/Interpreter/OptionValueSInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
@@ -68,11 +68,10 @@ class OptionValueSInt64 : public Cloneable<OptionValueSInt64, OptionValue> {
   }
 
   bool SetDefaultValue(int64_t value) {
-    if (value >= m_min_value && value <= m_max_value) {
-      m_default_value = value;
-      return true;
-    }
-    return false;
+    assert(value >= m_min_value && value <= m_max_value &&
+           "disallowed default value");
+    m_default_value = value;
+    return true;
   }
 
   void SetMinimumValue(int64_t v) { m_min_value = v; }

diff  --git a/lldb/include/lldb/Interpreter/OptionValueUInt64.h b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
index 07076075790c674..5cccff177cb1d60 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
@@ -73,18 +73,17 @@ class OptionValueUInt64 : public Cloneable<OptionValueUInt64, OptionValue> {
   }
 
   bool SetDefaultValue(uint64_t value) {
-    if (value >= m_min_value && value <= m_max_value) {
-      m_default_value = value;
-      return true;
-    }
-    return false;
+    assert(value >= m_min_value && value <= m_max_value &&
+           "disallowed default value");
+    m_default_value = value;
+    return true;
   }
 
-  void SetMinimumValue(int64_t v) { m_min_value = v; }
+  void SetMinimumValue(uint64_t v) { m_min_value = v; }
 
   uint64_t GetMinimumValue() const { return m_min_value; }
 
-  void SetMaximumValue(int64_t v) { m_max_value = v; }
+  void SetMaximumValue(uint64_t v) { m_max_value = v; }
 
   uint64_t GetMaximumValue() const { return m_max_value; }
 


        


More information about the lldb-commits mailing list