|
|
|
[PATCH 2/3] evaluate: warn on identical exprs around '||' | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
Same as prev, but for || operator.
Signed-off-by: Chris Forbes <chrisf@xxxxxxxxx>
---
evaluate.c | 4 ++++
validation/check_identical_exprs_on_or.c | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
create mode 100644 validation/check_identical_exprs_on_or.c
diff --git a/evaluate.c b/evaluate.c
index 08f6ae6..11de7aa 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -985,6 +985,10 @@ static struct symbol *evaluate_logical(struct expression *expr)
expr_equiv(expr->left, expr->right)) {
warning(expr->pos, "identical expressions on both "
"sides of '&&'");
+ } else if (expr->op == SPECIAL_LOGICAL_OR &&
+ expr_equiv(expr->left, expr->right)) {
+ warning(expr->pos, "identical expressions on both "
+ "sides of '||'");
}
}
diff --git a/validation/check_identical_exprs_on_or.c b/validation/check_identical_exprs_on_or.c
new file mode 100644
index 0000000..74fe226
--- /dev/null
+++ b/validation/check_identical_exprs_on_or.c
@@ -0,0 +1,24 @@
+extern void bar(void);
+
+static void foo(void *a, void *b, void *c)
+{
+ if (a || a) /* should warn */
+ bar();
+
+ if (a || b) /* should not warn */
+ bar();
+
+ if ((a == b) || (a == b)) /* should warn */
+ bar();
+
+ if ((a == b) || (b == c)) /* should not warn */
+ bar();
+}
+/*
+ * check-name: A warning should be issued for identical expressions on both sides of the '||' operator.
+ *
+ * check-error-start
+check_identical_exprs_on_or.c:5:15: warning: identical expressions on both sides of '||'
+check_identical_exprs_on_or.c:11:22: warning: identical expressions on both sides of '||'
+ * check-error-end
+ */
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Newbies FAQ] [Kernel List] [Site Home] [IETF Annouce] [DCCP] [Netdev] [Networking] [Security] [Bugtraq] [Photo] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Linux SCSI] [DDR & Rambus] [Trinity Fuzzer Tool]