linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Sparse fooled by double semicolon
@ 2007-01-31  4:50 Pavel Roskin
  2007-01-31  6:58 ` [PATCH] " Christopher Li
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Roskin @ 2007-01-31  4:50 UTC (permalink / raw)
  To: linux-sparse

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.

-- 
Regards,
Pavel Roskin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Sparse fooled by double semicolon
  2007-01-31  4:50 Sparse fooled by double semicolon Pavel Roskin
@ 2007-01-31  6:58 ` Christopher Li
  2007-01-31  7:17   ` [PATCH](take II) " Christopher Li
  2007-01-31  7:43   ` [PATCH] " Pavel Roskin
  0 siblings, 2 replies; 6+ messages in thread
From: Christopher Li @ 2007-01-31  6:58 UTC (permalink / raw)
  To: Pavel Roskin; +Cc: linux-sparse, Josh Triplett

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.

Signed-Off-By: Christopher Li<spase@chrisli.org>

Index: sparse/parse.c
===================================================================
--- sparse.orig/parse.c	2007-01-29 14:46:09.000000000 -0800
+++ sparse/parse.c	2007-01-30 23:11:42.000000000 -0800
@@ -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;
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH](take II) Sparse fooled by double semicolon
  2007-01-31  6:58 ` [PATCH] " Christopher Li
@ 2007-01-31  7:17   ` Christopher Li
  2007-01-31  7:46     ` Pavel Roskin
  2007-02-23  3:43     ` Josh Triplett
  2007-01-31  7:43   ` [PATCH] " Pavel Roskin
  1 sibling, 2 replies; 6+ messages in thread
From: Christopher Li @ 2007-01-31  7:17 UTC (permalink / raw)
  To: Pavel Roskin; +Cc: linux-sparse, Josh Triplett

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.

Signed-Off-By: Christopher Li<spase@chrisli.org>

Index: sparse/parse.c
===================================================================
--- sparse.orig/parse.c	2007-01-30 23:28:24.000000000 -0800
+++ sparse/parse.c	2007-01-30 23:34:21.000000000 -0800
@@ -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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Sparse fooled by double semicolon
  2007-01-31  6:58 ` [PATCH] " Christopher Li
  2007-01-31  7:17   ` [PATCH](take II) " Christopher Li
@ 2007-01-31  7:43   ` Pavel Roskin
  1 sibling, 0 replies; 6+ messages in thread
From: Pavel Roskin @ 2007-01-31  7:43 UTC (permalink / raw)
  To: Christopher Li; +Cc: linux-sparse, Josh Triplett

On Tue, 2007-01-30 at 22:58 -0800, Christopher Li wrote:
> Good catch, can you please try the following patch?

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

-- 
Regards,
Pavel Roskin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH](take II) Sparse fooled by double semicolon
  2007-01-31  7:17   ` [PATCH](take II) " Christopher Li
@ 2007-01-31  7:46     ` Pavel Roskin
  2007-02-23  3:43     ` Josh Triplett
  1 sibling, 0 replies; 6+ messages in thread
From: Pavel Roskin @ 2007-01-31  7:46 UTC (permalink / raw)
  To: Christopher Li; +Cc: linux-sparse, Josh Triplett

On Tue, 2007-01-30 at 23:17 -0800, Christopher Li wrote:
> Actually, this version is better because it handle semicolon
> as the first member as well.

That's working too.

-- 
Regards,
Pavel Roskin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH](take II) Sparse fooled by double semicolon
  2007-01-31  7:17   ` [PATCH](take II) " Christopher Li
  2007-01-31  7:46     ` Pavel Roskin
@ 2007-02-23  3:43     ` Josh Triplett
  1 sibling, 0 replies; 6+ messages in thread
From: Josh Triplett @ 2007-02-23  3:43 UTC (permalink / raw)
  To: Christopher Li; +Cc: Pavel Roskin, linux-sparse

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

Christopher Li wrote:
> 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.
> 
> Signed-Off-By: Christopher Li<spase@chrisli.org>

Applied, along with the test case.

- Josh Triplett



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-02-23  3:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-31  4:50 Sparse fooled by double semicolon Pavel Roskin
2007-01-31  6:58 ` [PATCH] " Christopher Li
2007-01-31  7:17   ` [PATCH](take II) " Christopher Li
2007-01-31  7:46     ` Pavel Roskin
2007-02-23  3:43     ` Josh Triplett
2007-01-31  7:43   ` [PATCH] " Pavel Roskin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).