threads / patch / 31964

patchbuiltin/config.c: Fix a sparse warning

Subject: [PATCH] builtin/config.c: Fix a sparse warning

## tl;dr

2 messages between Oct 28, 2012 and Oct 29, 2012. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Ramsay Jones· Oct 28, 2012, 21:05 UTC · lore

Sparse issues an "Using plain integer as NULL pointer" warning while checking a 'struct strbuf_list' initializer expression. The initial field of the struct has pointer type, but the initializer expression is given as '{0}'. In order to suppress the warning, we simply replace the initializer with '{NULL}'.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
Hi Jeff,

I try to catch these types of warnings while the patches are still in the pu branch. I don't know how I missed this one, but I don't remember your 'jk/config-ignore-duplicates' branch being in pu.

Sorry about that.

ATB, Ramsay Jones

 builtin/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/config.c +1 −1
diff --git a/builtin/config.c b/builtin/config.c
index f881053..e796af4 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -165,7 +165,7 @@ static int collect_config(const char *key_, const char *value_, void *cb)
 static int get_value(const char *key_, const char *regex_)
 {
 	int ret = CONFIG_GENERIC_ERROR;
-	struct strbuf_list values = {0};
+	struct strbuf_list values = {NULL};
 	int i;
 
 	if (use_key_regexp) {
-- 
1.8.0
Jeff King· Oct 29, 2012, 05:47 UTC · re: Ramsay Jones · lore

Re: [PATCH] builtin/config.c: Fix a sparse warning

On Sun, Oct 28, 2012 at 09:05:25PM +0000, Ramsay Jones wrote:
Show 5 quoted lines
> Sparse issues an "Using plain integer as NULL pointer" warning while
> checking a 'struct strbuf_list' initializer expression. The initial
> field of the struct has pointer type, but the initializer expression
> is given as '{0}'. In order to suppress the warning, we simply replace
> the initializer with '{NULL}'.

I slightly disagree with sparse here, as the 0 here is not about explicitly setting the pointer, but is an idiomatic shorthand for requesting static-like initialization (and it is purely a style thing, not a bug, as 0 is a fine null pointer, even on platforms without all-bits-zero null pointers).

But I think it is still worth changing in the name of sparse-cleanliness. Thanks.

Show 5 quoted lines
> I try to catch these types of warnings while the patches are still
> in the pu branch. I don't know how I missed this one, but I don't
> remember your 'jk/config-ignore-duplicates' branch being in pu.
> 
> Sorry about that.

Not your fault. The time during which it would have been in pu was after Junio left but before I had pushed out my pu. I did have it locally in pu for a bit, but it ended up on next the first time it was published, because the series had already received favorable review on the list in the meantime.

But I forgot that some people may first see the new code via the published pu, not the list (e.g., if they are pulling and building pu routinely with sparse). I'll try to be better about making sure stuff is actually published in pu for a cycle before merging to next.

-Peff

← back to recent threads