Skip to content

Commit 8b9f677

Browse files
authored
Merge pull request #494 from rvermeulen/rvermeulen/fix-issue-#319
Exclude non integer literals in RULE-7-3
2 parents d9f0911 + b9a6308 commit 8b9f677

File tree

10 files changed

+14
-4
lines changed

10 files changed

+14
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Reuse the `IntegerLiteral` class
2+
import codingstandards.cpp.Cpp14Literal
3+
4+
class IntegerLiteral = Cpp14Literal::IntegerLiteral;

c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17+
import codingstandards.c.Literals
1718

18-
from Literal l
19+
from IntegerLiteral l
1920
where
2021
not isExcluded(l, SyntaxPackage::lowercaseCharacterLUsedInLiteralSuffixQuery()) and
21-
not l instanceof StringLiteral and
2222
exists(l.getValueText().indexOf("l"))
2323
select l, "Lowercase 'l' used as a literal suffix."

c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.expected

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This test case was added to validate FP report [#319](https://github.com/github/codeql-coding-standards/issues/319) that occurs when this rule is run on a translation unit with language mode c++.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options:--clang -std=c++14 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../../cpp/common/test/includes/standard-library
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int x = false; // COMPLIANT - reported as FP in #319

c/misra/test/rules/RULE-7-3/test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ long d9 = 001LU; // COMPLIANT
4141

4242
char *e1 = "";
4343
char *e2 = "ul";
44-
char *e3 = "UL";
44+
char *e3 = "UL";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`RULE-7-3`: `c/misra/lowercase-character-l-used-in-literal-suffix`
2+
- Exclude non integer literals. This removes a false positive triggered when analyzing C++ code containing the `false` literal.

cpp/common/src/codingstandards/cpp/Cpp14Literal.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Cpp14Literal {
2424
* Octal literals must always start with the digit `0`.
2525
*/
2626
class OctalLiteral extends IntegerLiteral {
27-
OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']+[uUlL]*\\s*") }
27+
OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']*[uUlL]*\\s*") }
2828

2929
override string getAPrimaryQlClass() { result = "OctalLiteral" }
3030
}

0 commit comments

Comments
 (0)