{"thread":{"id":"34477","subject":"[PATCH] Fix some sparse warnings","startedAt":"2013-07-18T20:25:50Z","lastAt":"2013-07-21T20:58:58Z","messageCount":5,"participants":["Ramsay Jones","Jeff King","Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"223694","messageId":"51E84F4E.3050600@ramsay1.demon.co.uk","threadId":"34477","inReplyTo":null,"subject":"[PATCH] Fix some sparse warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-07-18T20:25:50Z","receivedAt":"2013-07-18T20:25:50Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSparse issues some \"Using plain integer as NULL pointer\" warnings.\nEach warning relates to the use of an '{0}' initialiser expression\nin the declaration of an 'struct object_info'. The first field of\nthis structure has pointer type. Thus, in order to suppress these\nwarnings, we replace the initialiser expression with '{NULL}'.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nThis was built on the next branch.\n\nATB,\nRamsay Jones\n\n\n sha1_file.c | 2 +-\n streaming.c | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 4c2365f..e4ab0a4 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2440,7 +2440,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)\n \n int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)\n {\n-\tstruct object_info oi = {0};\n+\tstruct object_info oi = {NULL};\n \n \toi.sizep = sizep;\n \treturn sha1_object_info_extended(sha1, &oi);\ndiff --git a/streaming.c b/streaming.c\nindex cac282f..5710065 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -135,7 +135,7 @@ struct git_istream *open_istream(const unsigned char *sha1,\n \t\t\t\t struct stream_filter *filter)\n {\n \tstruct git_istream *st;\n-\tstruct object_info oi = {0};\n+\tstruct object_info oi = {NULL};\n \tconst unsigned char *real = lookup_replace_object(sha1);\n \tenum input_source src = istream_source(real, type, &oi);\n \n-- \n1.8.3\n"},{"id":"223697","messageId":"20130718203640.GB15735@sigill.intra.peff.net","threadId":"34477","inReplyTo":"51E84F4E.3050600@ramsay1.demon.co.uk","subject":"Re: [PATCH] Fix some sparse warnings","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-07-18T20:36:41Z","receivedAt":"2013-07-18T20:36:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 18, 2013 at 09:25:50PM +0100, Ramsay Jones wrote:\n\n> Sparse issues some \"Using plain integer as NULL pointer\" warnings.\n> Each warning relates to the use of an '{0}' initialiser expression\n> in the declaration of an 'struct object_info'. The first field of\n> this structure has pointer type. Thus, in order to suppress these\n> warnings, we replace the initialiser expression with '{NULL}'.\n> \n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n\nAcked-by: Jeff King <peff@peff.net>\n\nI thought at first we would need one more for the new callsite I added\nin my series, but we use memset() in that instance, so it is fine.\n\n-Peff\n"},{"id":"223880","messageId":"51EAE463.4010705@ramsay1.demon.co.uk","threadId":"34477","inReplyTo":"20130718203640.GB15735@sigill.intra.peff.net","subject":"Re: [PATCH] Fix some sparse warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-07-20T19:26:27Z","receivedAt":"2013-07-20T19:26:27Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Jeff King wrote:\n> On Thu, Jul 18, 2013 at 09:25:50PM +0100, Ramsay Jones wrote:\n> \n>> Sparse issues some \"Using plain integer as NULL pointer\" warnings.\n>> Each warning relates to the use of an '{0}' initialiser expression\n>> in the declaration of an 'struct object_info'. The first field of\n>> this structure has pointer type. Thus, in order to suppress these\n>> warnings, we replace the initialiser expression with '{NULL}'.\n>>\n>> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n> \n> Acked-by: Jeff King <peff@peff.net>\n> \n> I thought at first we would need one more for the new callsite I added\n> in my series, but we use memset() in that instance, so it is fine.\n\nOn an almost unrelated note ... I am now getting the following sparse\nwarnings:\n\n    pack-revindex.c:105:23: warning: memset with byte count of 262144\n\nThis is a little annoying, since there is no way to turn this off. :(\n(which I consider a bug in sparse).\n\nSparse has special-case code to check calls to memset(), memcpy(),\ncopy_to_user() and copy_from_user(). The code that checks the byte\ncount argument looks like:\n\nstatic void check_byte_count(struct instruction *insn, pseudo_t count)\n{\n        if (!count)\n                return;\n        if (count->type == PSEUDO_VAL) {\n                long long val = count->value;\n                if (val <= 0 || val > 100000)\n                        warning(insn->pos, \"%s with byte count of %lld\",\n                                show_ident(insn->func->sym->ident), val);\n                return;\n        }\n        /* OK, we could try to do the range analysis here */\n}\n\nI will just ignore this for now. ;-)\n\nATB,\nRamsay Jones\n"},{"id":"223884","messageId":"20130721173936.GA10647@elie.Belkin","threadId":"34477","inReplyTo":"51E84F4E.3050600@ramsay1.demon.co.uk","subject":"Re: [PATCH] Fix some sparse warnings","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-07-21T17:39:37Z","receivedAt":"2013-07-21T17:39:37Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nRamsay Jones wrote:\n\n> Sparse issues some \"Using plain integer as NULL pointer\" warnings.\n> Each warning relates to the use of an '{0}' initialiser expression\n> in the declaration of an 'struct object_info'. The first field of\n> this structure has pointer type. Thus, in order to suppress these\n> warnings, we replace the initialiser expression with '{NULL}'.\n\nI agree that this is worth solving but the fix feels like a move in\nthe wrong direction.  Before this patch, the initialization says\n\"= {0}\", which basically means \"memset it to 0\".  Afterward, the\ninitializer depends on the order of fields in the struct.\n\nHow about something like the following?\n\ndiff --git i/cache.h w/cache.h\nindex f2915509..ba028b75 100644\n--- i/cache.h\n+++ w/cache.h\n@@ -1124,6 +1124,7 @@ struct object_info {\n \t\t} packed;\n \t} u;\n };\n+#define OBJECT_INFO_INIT { NULL, NULL, OI_CACHED, { { NULL, 0, 0 } } }\n extern int sha1_object_info_extended(const unsigned char *, struct object_info *);\n \n /* Dumb servers support */\ndiff --git i/sha1_file.c w/sha1_file.c\nindex 6baed676..2d812b8d 100644\n--- i/sha1_file.c\n+++ w/sha1_file.c\n@@ -2421,7 +2421,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)\n \n int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)\n {\n-\tstruct object_info oi = {0};\n+\tstruct object_info oi = OBJECT_INFO_INIT;\n \n \toi.sizep = sizep;\n \treturn sha1_object_info_extended(sha1, &oi);\ndiff --git i/streaming.c w/streaming.c\nindex cac282f0..b4c40ad9 100644\n--- i/streaming.c\n+++ w/streaming.c\n@@ -135,7 +135,7 @@ struct git_istream *open_istream(const unsigned char *sha1,\n \t\t\t\t struct stream_filter *filter)\n {\n \tstruct git_istream *st;\n-\tstruct object_info oi = {0};\n+\tstruct object_info oi = OBJECT_INFO_INIT;\n \tconst unsigned char *real = lookup_replace_object(sha1);\n \tenum input_source src = istream_source(real, type, &oi);\n \n"},{"id":"223889","messageId":"7vmwpfsk8d.fsf@alter.siamese.dyndns.org","threadId":"34477","inReplyTo":"20130721173936.GA10647@elie.Belkin","subject":"Re: [PATCH] Fix some sparse warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-21T20:58:58Z","receivedAt":"2013-07-21T20:58:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> How about something like the following?\n>\n> diff --git i/cache.h w/cache.h\n> index f2915509..ba028b75 100644\n> --- i/cache.h\n> +++ w/cache.h\n> @@ -1124,6 +1124,7 @@ struct object_info {\n>  \t\t} packed;\n>  \t} u;\n>  };\n> +#define OBJECT_INFO_INIT { NULL, NULL, OI_CACHED, { { NULL, 0, 0 } } }\n\nThere are quite a many hits from\n\n\t$ git grep '= { *NULL *};'\n\nonly some of which are \"char *var[] = { NULL }\", which is perfectly\nfine, but others are to initialise \"struct foo\" (or \"foo_t\" which is\ntypedef'ed) that share the same \"writing NULL means the initialiser\nknows the order of the fields\".\n\nI doubt if the above #define is a maintainable solution, and worse\nyet, thinking about the fact that such a macro is necessary only for\na structure whose first field happens to be of a pointer type, it\nstrongly suggests me that it is not conceptually the right thing to\ndo.\n\nCan't we have sparse fixed (or skip this specific warning) instead?\n"}]}