From: Zoltan Klinger <zoltan.klinger@gmail.com>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Cc: Junio C Hamano <gitster@pobox.com>,
GIT Mailing-list <git@vger.kernel.org>
Subject: Re: [PATCH] builtin/clean.c: Fix some sparse warnings
Date: Fri, 21 Dec 2012 23:31:03 +1100 [thread overview]
Message-ID: <CAKJhZwSLSbR2pTB67-KLtrtuFsq6HtBGdHbN8h6tLiXBKynQzg@mail.gmail.com> (raw)
In-Reply-To: <50D35A13.9080605@ramsay1.demon.co.uk>
Thanks, Ramsay. I am rewriting the whole patch to do things a better
way (as kindly suggested by Junio). So the print_filtered() function
is going to disappear, but thanks for pointing out the problems with
the existing code.
Cheers,
Zoltan
On 21 December 2012 05:33, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:
>
> Sparse issues two "Using plain integer as NULL pointer" warnings
> (lines 41 and 47).
>
> The first warning relates to the initializer expression in the
> declaration for the 'char *dir' variable. In order to suppress
> the warning, we simply replace the zero initializer with NULL.
>
> The second warning relates to an expression, as part of an if
> conditional, using the equality operator to compare the 'dir'
> variable to zero. In order to suppress the warning, we replace
> the 'dir == 0' expression with the more idiomatic '!dir'.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>
> Hi Zoltan,
>
> If you have already updated your patch and made this redundant
> (it's been a few days since I read the list or fetched git.git),
> please ignore this. Otherwise, could you please squash this into
> the new version of commit 16e4033e6 ("git-clean: Display more
> accurate delete messages", 17-12-2012).
>
> [BTW, in the same conditional expression you have an strncmp()
> call which doesn't quite follow the style/conventions of the
> existing code.]
>
> Thanks!
>
> ATB,
> Ramsay Jones
>
> builtin/clean.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index 1c25a75..0c603c8 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -38,13 +38,13 @@ static void print_filtered(const char *msg, struct string_list *lst)
> {
> int i;
> char *name;
> - char *dir = 0;
> + char *dir = NULL;
>
> sort_string_list(lst);
>
> for (i = 0; i < lst->nr; i++) {
> name = lst->items[i].string;
> - if (dir == 0 || strncmp(name, dir, strlen(dir)) != 0)
> + if (!dir || strncmp(name, dir, strlen(dir)) != 0)
> printf("%s %s\n", msg, name);
> if (name[strlen(name) - 1] == '/')
> dir = name;
> --
> 1.8.0
>
prev parent reply other threads:[~2012-12-21 12:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-20 18:33 [PATCH] builtin/clean.c: Fix some sparse warnings Ramsay Jones
2012-12-21 12:31 ` Zoltan Klinger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKJhZwSLSbR2pTB67-KLtrtuFsq6HtBGdHbN8h6tLiXBKynQzg@mail.gmail.com \
--to=zoltan.klinger@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ramsay@ramsay1.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).