From 0128b1702e5568df4ca66e61362c6c78a50f9ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20Dimitrijevi=C4=87?= Date: Wed, 28 Sep 2022 15:36:01 +0200 Subject: [PATCH] C++: Fix "LHS-end = RHS-begin" FP --- .../Likely Errors/CommaBeforeMisleadingIndentation.ql | 9 +++++---- .../CommaBeforeMisleadingIndentation/test.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql b/cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql index 900b08994c7..a786f4aec33 100644 --- a/cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql +++ b/cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql @@ -20,13 +20,14 @@ Expr normalizeExpr(Expr e) { else result = e } -from CommaExpr ce, Expr left, Expr right, int leftStartColumn, int rightStartColumn +from CommaExpr ce, Expr left, Expr right, Location leftLoc, Location rightLoc where ce.fromSource() and not isFromMacroDefinition(ce) and left = normalizeExpr(ce.getLeftOperand()) and right = normalizeExpr(ce.getRightOperand()) and - leftStartColumn = left.getLocation().getStartColumn() and - rightStartColumn = right.getLocation().getStartColumn() and - leftStartColumn > rightStartColumn + leftLoc = left.getLocation() and + rightLoc = right.getLocation() and + leftLoc.getEndLine() < rightLoc.getStartLine() and + leftLoc.getStartColumn() > rightLoc.getStartColumn() select right, "The indentation level after the comma can be misleading (for some tab sizes)." diff --git a/cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp b/cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp index 8aae39668f6..642161f6549 100644 --- a/cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp +++ b/cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp @@ -113,7 +113,7 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int)) int k = (foo( i++ - ), j++); // GOOD? [FALSE POSITIVE] + ), j++); // GOOD? // Weird case: