* [PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings
@ 2015-05-19 22:16 Ramsay Jones
2015-05-20 17:04 ` David Turner
0 siblings, 1 reply; 2+ messages in thread
From: Ramsay Jones @ 2015-05-19 22:16 UTC (permalink / raw)
To: David Turner; +Cc: Junio C Hamano, GIT Mailing-list
Commit 811cd77b ("tree-walk: learn get_tree_entry_follow_symlinks",
14-05-2015) introduced a new function to locate an object by path
while following symlinks in the repository. However, sparse now
issues some "Using plain integer as NULL pointer" warnings as
follows:
SP tree-walk.c
tree-walk.c:517:31: warning: Using plain integer as NULL pointer
tree-walk.c:521:28: warning: Using plain integer as NULL pointer
The first warning relates to the use of an '{0}' initializer for
the 'struct tree_desc' t. The first field of this structure has
pointer type. A simple solution would replace the initializer
expression with '{NULL}'. However, we choose to remove the
initializer expression and make the initialization more explicit
with a call to the 'init_tree_desc' function.
The second warning relates to the '0' initializer for the buf
field of the 'result_path' strbuf pointer. A simple solution
would replace this initializer with 'NULL'. However, this would
violate a strbuf invariant that the 'buf' field is never NULL.
(see strbuf documentation in strbuf.h header.) Assuming the
documentation of 'get_tree_entry_follow_symlinks' regarding the
'result_path' parameter is observed by callers (ie that the
parameter points to an _unitialized_ strbuf), a better solution
is to simply call the 'strbuf_init' function.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
Hi David,
If you need to re-roll the patches in your 'dt/cat-file-follow-symlinks'
branch, could you please squash this, or something like this, into the
relevant patch (commit 811cd77b).
Thanks!
ATB,
Ramsay Jones
tree-walk.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tree-walk.c b/tree-walk.c
index 8031f3a..6dccd2d 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -514,13 +514,12 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
ssize_t parents_nr = 0;
unsigned char current_tree_sha1[20];
struct strbuf namebuf = STRBUF_INIT;
- struct tree_desc t = {0};
+ struct tree_desc t;
int follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS;
int i;
- result_path->buf = 0;
- result_path->alloc = 0;
- result_path->len = 0;
+ init_tree_desc(&t, NULL, 0UL);
+ strbuf_init(result_path, 0);
strbuf_addstr(&namebuf, name);
hashcpy(current_tree_sha1, tree_sha1);
--
2.4.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings
2015-05-19 22:16 [PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings Ramsay Jones
@ 2015-05-20 17:04 ` David Turner
0 siblings, 0 replies; 2+ messages in thread
From: David Turner @ 2015-05-20 17:04 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list
re-rolled, thanks.
On Tue, 2015-05-19 at 23:16 +0100, Ramsay Jones wrote:
> Commit 811cd77b ("tree-walk: learn get_tree_entry_follow_symlinks",
> 14-05-2015) introduced a new function to locate an object by path
> while following symlinks in the repository. However, sparse now
> issues some "Using plain integer as NULL pointer" warnings as
> follows:
>
> SP tree-walk.c
> tree-walk.c:517:31: warning: Using plain integer as NULL pointer
> tree-walk.c:521:28: warning: Using plain integer as NULL pointer
>
> The first warning relates to the use of an '{0}' initializer for
> the 'struct tree_desc' t. The first field of this structure has
> pointer type. A simple solution would replace the initializer
> expression with '{NULL}'. However, we choose to remove the
> initializer expression and make the initialization more explicit
> with a call to the 'init_tree_desc' function.
>
> The second warning relates to the '0' initializer for the buf
> field of the 'result_path' strbuf pointer. A simple solution
> would replace this initializer with 'NULL'. However, this would
> violate a strbuf invariant that the 'buf' field is never NULL.
> (see strbuf documentation in strbuf.h header.) Assuming the
> documentation of 'get_tree_entry_follow_symlinks' regarding the
> 'result_path' parameter is observed by callers (ie that the
> parameter points to an _unitialized_ strbuf), a better solution
> is to simply call the 'strbuf_init' function.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>
> Hi David,
>
> If you need to re-roll the patches in your 'dt/cat-file-follow-symlinks'
> branch, could you please squash this, or something like this, into the
> relevant patch (commit 811cd77b).
>
> Thanks!
>
> ATB,
> Ramsay Jones
>
> tree-walk.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/tree-walk.c b/tree-walk.c
> index 8031f3a..6dccd2d 100644
> --- a/tree-walk.c
> +++ b/tree-walk.c
> @@ -514,13 +514,12 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
> ssize_t parents_nr = 0;
> unsigned char current_tree_sha1[20];
> struct strbuf namebuf = STRBUF_INIT;
> - struct tree_desc t = {0};
> + struct tree_desc t;
> int follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS;
> int i;
>
> - result_path->buf = 0;
> - result_path->alloc = 0;
> - result_path->len = 0;
> + init_tree_desc(&t, NULL, 0UL);
> + strbuf_init(result_path, 0);
> strbuf_addstr(&namebuf, name);
> hashcpy(current_tree_sha1, tree_sha1);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-20 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-19 22:16 [PATCH] tree-walk.c: fix some sparse 'NULL pointer' warnings Ramsay Jones
2015-05-20 17:04 ` David Turner
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).