`RULE-10-4`: False negatives as rule does not currently consider ternaries

Open Beginner friendly
#821 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
devtools

Research direction

Inspect MisraExpressions.qll, starting with OperationWithUsualArithmeticConversions and the RULE-10-4 query or tests. Confirm how binary and assignment arithmetic operations expose operands, then make the conditional-expression case cover operands 2 and 3 and verify the provided ternary example is no longer a false negative.

Written by the indexing model from the issue text.

Description

Difficulty-Low false positive/false negative false-negative Impact-Low Standard-MISRA-C
Affected rules
  • RULE-10-4
Description

The text states that the rule applies to usual arithmetic conversions, and the c spec states that for a ? b : c the usual arithmetic conversions are performed on operands b and c. However, OperationWithUsualArithmeticConversions from MisraExpressions.qll holds for this instanceof BinaryOperation and ... or this instanceof AssignArithmeticOperation, it should also hold for this instanceof ConditionalExpr and getLeftOperand() / getRightOperand() should return operands 2 & 3.

Example
void example_function() {
  int x;
  float y;
  bool b;

  b ? x : y; // FALSE NEGATIVE
}
Dominant language
CodeQL
Stars
227
Forks
82
Avg merge
6d 7h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql-coding-standards

All issues in github/codeql-coding-standards

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.