{"thread":{"id":"39377","subject":"[PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings","startedAt":"2015-05-19T22:16:19Z","lastAt":"2015-05-20T17:04:21Z","messageCount":2,"participants":["Ramsay Jones","David Turner"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"261615","messageId":"555BB633.8030204@ramsay1.demon.co.uk","threadId":"39377","inReplyTo":null,"subject":"[PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2015-05-19T22:16:19Z","receivedAt":"2015-05-19T22:16:19Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nCommit 811cd77b (\"tree-walk: learn get_tree_entry_follow_symlinks\",\n14-05-2015) introduced a new function to locate an object by path\nwhile following symlinks in the repository. However, sparse now\nissues some \"Using plain integer as NULL pointer\" warnings as\nfollows:\n\n      SP tree-walk.c\n  tree-walk.c:517:31: warning: Using plain integer as NULL pointer\n  tree-walk.c:521:28: warning: Using plain integer as NULL pointer\n\nThe first warning relates to the use of an '{0}' initializer for\nthe 'struct tree_desc' t. The first field of this structure has\npointer type. A simple solution would replace the initializer\nexpression with '{NULL}'. However, we choose to remove the\ninitializer expression and make the initialization more explicit\nwith a call to the 'init_tree_desc' function.\n\nThe second warning relates to the '0' initializer for the buf\nfield of the 'result_path' strbuf pointer. A simple solution\nwould replace this initializer with 'NULL'. However, this would\nviolate a strbuf invariant that the 'buf' field is never NULL.\n(see strbuf documentation in strbuf.h header.) Assuming the\ndocumentation of 'get_tree_entry_follow_symlinks' regarding the\n'result_path' parameter is observed by callers (ie that the\nparameter points to an _unitialized_ strbuf), a better solution\nis to simply call the 'strbuf_init' function.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi David,\n\nIf you need to re-roll the patches in your 'dt/cat-file-follow-symlinks'\nbranch, could you please squash this, or something like this, into the\nrelevant patch (commit 811cd77b).\n\nThanks!\n\nATB,\nRamsay Jones\n\n tree-walk.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 8031f3a..6dccd2d 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -514,13 +514,12 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s\n \tssize_t parents_nr = 0;\n \tunsigned char current_tree_sha1[20];\n \tstruct strbuf namebuf = STRBUF_INIT;\n-\tstruct tree_desc t = {0};\n+\tstruct tree_desc t;\n \tint follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS;\n \tint i;\n \n-\tresult_path->buf = 0;\n-\tresult_path->alloc = 0;\n-\tresult_path->len = 0;\n+\tinit_tree_desc(&t, NULL, 0UL);\n+\tstrbuf_init(result_path, 0);\n \tstrbuf_addstr(&namebuf, name);\n \thashcpy(current_tree_sha1, tree_sha1);\n \n-- \n2.4.0\n"},{"id":"261671","messageId":"1432141461.15896.6.camel@ubuntu","threadId":"39377","inReplyTo":"555BB633.8030204@ramsay1.demon.co.uk","subject":"Re: [PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings","fromName":"David Turner","fromEmail":"dturner@twopensource.com","sentAt":"2015-05-20T17:04:21Z","receivedAt":"2015-05-20T17:04:21Z","isPatch":true,"sender":{"key":"novalis@novalis.org","avatar":"https://avatars.githubusercontent.com/u/77003?v=4"},"body":"re-rolled, thanks.\n\nOn Tue, 2015-05-19 at 23:16 +0100, Ramsay Jones wrote:\n> Commit 811cd77b (\"tree-walk: learn get_tree_entry_follow_symlinks\",\n> 14-05-2015) introduced a new function to locate an object by path\n> while following symlinks in the repository. However, sparse now\n> issues some \"Using plain integer as NULL pointer\" warnings as\n> follows:\n> \n>       SP tree-walk.c\n>   tree-walk.c:517:31: warning: Using plain integer as NULL pointer\n>   tree-walk.c:521:28: warning: Using plain integer as NULL pointer\n> \n> The first warning relates to the use of an '{0}' initializer for\n> the 'struct tree_desc' t. The first field of this structure has\n> pointer type. A simple solution would replace the initializer\n> expression with '{NULL}'. However, we choose to remove the\n> initializer expression and make the initialization more explicit\n> with a call to the 'init_tree_desc' function.\n> \n> The second warning relates to the '0' initializer for the buf\n> field of the 'result_path' strbuf pointer. A simple solution\n> would replace this initializer with 'NULL'. However, this would\n> violate a strbuf invariant that the 'buf' field is never NULL.\n> (see strbuf documentation in strbuf.h header.) Assuming the\n> documentation of 'get_tree_entry_follow_symlinks' regarding the\n> 'result_path' parameter is observed by callers (ie that the\n> parameter points to an _unitialized_ strbuf), a better solution\n> is to simply call the 'strbuf_init' function.\n> \n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n> ---\n> \n> Hi David,\n> \n> If you need to re-roll the patches in your 'dt/cat-file-follow-symlinks'\n> branch, could you please squash this, or something like this, into the\n> relevant patch (commit 811cd77b).\n> \n> Thanks!\n> \n> ATB,\n> Ramsay Jones\n> \n>  tree-walk.c | 7 +++----\n>  1 file changed, 3 insertions(+), 4 deletions(-)\n> \n> diff --git a/tree-walk.c b/tree-walk.c\n> index 8031f3a..6dccd2d 100644\n> --- a/tree-walk.c\n> +++ b/tree-walk.c\n> @@ -514,13 +514,12 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s\n>  \tssize_t parents_nr = 0;\n>  \tunsigned char current_tree_sha1[20];\n>  \tstruct strbuf namebuf = STRBUF_INIT;\n> -\tstruct tree_desc t = {0};\n> +\tstruct tree_desc t;\n>  \tint follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS;\n>  \tint i;\n>  \n> -\tresult_path->buf = 0;\n> -\tresult_path->alloc = 0;\n> -\tresult_path->len = 0;\n> +\tinit_tree_desc(&t, NULL, 0UL);\n> +\tstrbuf_init(result_path, 0);\n>  \tstrbuf_addstr(&namebuf, name);\n>  \thashcpy(current_tree_sha1, tree_sha1);\n>  \n"}]}