[Lldb-commits] [lldb] 2ba3fe7 - [lldb] Fix incorrect uses of logical operator in 'if' condition check (NFC) (#94779)

via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 25 04:29:42 PDT 2024


Author: Shivam Gupta
Date: 2024-07-25T16:59:39+05:30
New Revision: 2ba3fe7356f065757a2279f65e4ef5c8f1476293

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

LOG: [lldb] Fix incorrect uses of logical operator in 'if' condition check (NFC) (#94779)

The condition checking for missing class name, interpreter dictionary,
and script object incorrectly used logical AND (&&), which could never
be true to enter the 'if' block.

This commit uses separate if conditions for each class name, interpreter
dictionary, and script object.

Cought by cppcheck -

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h:89:11:
warning: Identical inner 'if' condition is always true.
[identicalInnerCondition]

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h:91:16:
warning: Identical inner 'if' condition is always true.
[identicalInnerCondition]

Fix #89195

---------

Co-authored-by: Shivam Gupta <shivma98.tkg at gmail.com>

Added: 
    

Modified: 
    lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index e1a3156d10afd..2667f73516ba3 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -85,14 +85,15 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
     bool has_class_name = !class_name.empty();
     bool has_interpreter_dict =
         !(llvm::StringRef(m_interpreter.GetDictionaryName()).empty());
-    if (!has_class_name && !has_interpreter_dict && !script_obj) {
-      if (!has_class_name)
-        return create_error("Missing script class name.");
-      else if (!has_interpreter_dict)
-        return create_error("Invalid script interpreter dictionary.");
-      else
-        return create_error("Missing scripting object.");
-    }
+
+    if (!has_class_name)
+      return create_error("Missing script class name.");
+
+    if (!has_interpreter_dict)
+      return create_error("Invalid script interpreter dictionary.");
+
+    if (!script_obj)
+      return create_error("Missing scripting object.");
 
     Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
                    Locker::FreeLock);


        


More information about the lldb-commits mailing list