[PATCH 2/3] warn on empty assignments

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

 



Currently sparse accepts an empty assignment like:
	a = ;

Make this an error.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 expression.c                | 6 +++++-
 validation/bad-assignment.c | 1 +
 validation/empty-assign.c   | 1 -
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/expression.c b/expression.c
index 1160cd9cc593..ecbdd18eb402 100644
--- a/expression.c
+++ b/expression.c
@@ -937,10 +937,14 @@ struct token *assignment_expression(struct token *token, struct expression **tre
 		for (i = 0; i < ARRAY_SIZE(assignments); i++)
 			if (assignments[i] == op) {
 				struct expression * expr = alloc_expression(token->pos, EXPR_ASSIGNMENT);
+				struct token *next = token->next;
 				expr->left = *tree;
 				expr->op = op;
 				*tree = expr;
-				return assignment_expression(token->next, &expr->right);
+				token = assignment_expression(next, &expr->right);
+				if (token == next)
+					expression_error(expr, "expression expected before '%s'", show_token(token));
+				return token;
 			}
 	}
 	return token;
diff --git a/validation/bad-assignment.c b/validation/bad-assignment.c
index 71938db7c4f5..959712beda94 100644
--- a/validation/bad-assignment.c
+++ b/validation/bad-assignment.c
@@ -8,6 +8,7 @@ static int foo(int a)
  * check-name: bad assignment
  *
  * check-error-start
+bad-assignment.c:3:11: error: expression expected before '\'
 bad-assignment.c:3:13: error: Expected ; at end of statement
 bad-assignment.c:3:13: error: got \
  * check-error-end
diff --git a/validation/empty-assign.c b/validation/empty-assign.c
index 48ac626ddaed..d1c3884f71e8 100644
--- a/validation/empty-assign.c
+++ b/validation/empty-assign.c
@@ -6,7 +6,6 @@ static int foo(int a)
 
 /*
  * check-name: empty-assign
- * check-known-to-fail
  *
  * check-error-start
 empty-assign.c:3:11: error: expression expected before ';'
-- 
2.27.0




[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