Skip to contentSkip to conversation

Sparse fooled by double semicolon

DISCUSSION Pavel Roskin 3 participants 6 messages Jan 31, 2007 – Feb 23, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

Hello!

I have reduced a spurious sparse message to the following test:

#include <string.h>
void test(void)

{
	struct { int foo;; } val;
	memset(&val, 0, sizeof(val));
}

Running sparse on this code gives:

test.c:5:8: warning: memset with byte count of 0

Replacing two semicolons with one fixes the warning. That's the current sparse (006eff06c7adcfb0d06c6fadf6e9b64f0488b2bf) with no local changes.

Signature · 2 lines
Regards,
Pavel Roskin
maintainer
#1 lore raw

Good catch, can you please try the following patch?

Chris

Fix double semicolon in struct declare

Pavel discover this test case:
#include <string.h>
void test(void)

{
       struct { int foo;; } val;
       memset(&val, 0, sizeof(val));
}

Sparse creates a member with empty ctype. We should skip that.

parse.c +2 -1
Index: sparse/parse.c
===================================================================
@@ -1039,7 +1039,8 @@ static struct token *struct_declaration_
 			sparse_error(token->pos, "expected ; at end of declaration");
 			break;
 		}
-		token = token->next;
+		while(match_op(token, ';'))
+			token = token->next;
 	}
 	return token;
 }
#2 lore raw
Quoted 1 line · Christopher Li

Good catch, can you please try the following patch?

Good fix, it's working! Even on the original code. Thank you!

Signature · 2 lines
Regards,
Pavel Roskin
maintainer
#3 lore raw

Re: [PATCH](take II) Sparse fooled by double semicolon

In reply to Christopher Li

Actually, this version is better because it handle semicolon as the first member as well.

Fix double semicolon in struct declare

Pavel discover this test case:
#include <string.h>
void test(void)

{
       struct { int foo;; } val;
       memset(&val, 0, sizeof(val));
}

Sparse ends up create a node with empty ctype in the member list. Skip that seems fix it.

parse.c +2 -1
Index: sparse/parse.c
===================================================================
@@ -1034,7 +1034,8 @@ static struct token *declaration_list(st
 static struct token *struct_declaration_list(struct token *token, struct symbol_list **list)
 {
 	while (!match_op(token, '}')) {
-		token = declaration_list(token, list);
+		if (!match_op(token, ';'))
+			token = declaration_list(token, list);
 		if (!match_op(token, ';')) {
 			sparse_error(token->pos, "expected ; at end of declaration");
 			break;
#4 lore raw

Re: [PATCH](take II) Sparse fooled by double semicolon

Quoted 2 lines · Christopher Li

Actually, this version is better because it handle semicolon as the first member as well.

That's working too.

Signature · 2 lines
Regards,
Pavel Roskin
#5 lore raw

Re: [PATCH](take II) Sparse fooled by double semicolon

In reply to Christopher Li
Quoted 13 lines · Christopher Li

Actually, this version is better because it handle semicolon as the first member as well.

Fix double semicolon in struct declare

Pavel discover this test case:
#include <string.h>
void test(void)

{
       struct { int foo;; } val;
       memset(&val, 0, sizeof(val));
}
Quoted 4 lines

Sparse ends up create a node with empty ctype in the member list. Skip that seems fix it.

Applied, along with the test case.

- Josh Triplett