Sparse fooled by double semicolon
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
Christopher Li
maintainerGood 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
@@ -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; }
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
Christopher Li
maintainerRe: [PATCH](take II) Sparse fooled by double semicolon
In reply to Christopher LiActually, 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
@@ -1034,7 +1034,8 @@ static struct token *declaration_list(ststatic 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 ;
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
Re: [PATCH](take II) Sparse fooled by double semicolon
In reply to Christopher LiQuoted 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.
Signed-off-by Christopher Li<[email protected]>
Applied, along with the test case.
- Josh Triplett