[PATCH v2 4/8] div0: also check for compound assignments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 expand.c                 | 12 ++++++++++++
 validation/div-by-zero.c |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/expand.c b/expand.c
index 0b528ea5a..5bbab17a9 100644
--- a/expand.c
+++ b/expand.c
@@ -559,6 +559,18 @@ static int expand_assignment(struct expression *expr)
 {
 	expand_expression(expr->left);
 	expand_expression(expr->right);
+	if (!conservative) {
+		switch (expr->op) {
+		case SPECIAL_DIV_ASSIGN:
+		case SPECIAL_MOD_ASSIGN:
+			if (expr->right->type != EXPR_VALUE)
+				break;
+			if (expr->right->value)
+				break;
+			warning(expr->pos, "division by zero");
+			break;
+		}
+	}
 	return SIDE_EFFECTS;
 }
 
diff --git a/validation/div-by-zero.c b/validation/div-by-zero.c
index 500ceb8eb..bd8d0dfdf 100644
--- a/validation/div-by-zero.c
+++ b/validation/div-by-zero.c
@@ -59,8 +59,14 @@ div-by-zero.c:17:30: warning: division by zero
 div-by-zero.c:18:30: warning: division by zero
 div-by-zero.c:19:30: warning: division by zero
 div-by-zero.c:21:42: warning: division by zero
+div-by-zero.c:22:30: warning: division by zero
 div-by-zero.c:25:42: warning: division by zero
+div-by-zero.c:26:30: warning: division by zero
+div-by-zero.c:29:42: warning: division by zero
+div-by-zero.c:30:42: warning: division by zero
 div-by-zero.c:35:37: warning: division by zero
 div-by-zero.c:36:37: warning: division by zero
+div-by-zero.c:37:37: warning: division by zero
+div-by-zero.c:38:37: warning: division by zero
  * check-error-end
  */
-- 
2.13.0

--
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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux