Skip to content

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h:89: possible && and || mixup ? #89195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcb314 opened this issue Apr 18, 2024 · 2 comments · Fixed by #94779

Comments

@dcb314
Copy link

dcb314 commented Apr 18, 2024

Source code analyser cppcheck says:

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

Source code is

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.");

I think the original coder wanted something like:

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.");
@dcb314 dcb314 added the lldb label Apr 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2024

@llvm/issue-subscribers-lldb

Author: None (dcb314)

Source code analyser cppcheck says:

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

Source code is

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.");

I think the original coder wanted something like:

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.");

@DavidSpickett
Copy link
Collaborator

@medismailben

xgupta added a commit to xgupta/llvm-project that referenced this issue Jun 7, 2024
@xgupta xgupta closed this as completed in 2ba3fe7 Jul 25, 2024
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
… (NFC) (#94779)

Summary:
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 <[email protected]>

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants