[PATCH 0/3] Fix some issues found by Coverity

John Keeping john at keeping.me.uk
Sun Jan 17 21:25:36 CET 2016


On Sun, Jan 17, 2016 at 05:19:04PM +0100, Jason A. Donenfeld wrote:
> So there is now only 1 issue remaining: 13839.
> 
> static void add_commit(struct string_list *authors, struct commit *commit,
>         const struct cgit_period *period)
> {
>         struct commitinfo *info;
>         struct string_list_item *author, *item;
>         struct authorstat *authorstat;
>         struct string_list *items;
>         char *tmp;
>         struct tm *date;
>         time_t t;
> 
>         info = cgit_parse_commit(commit);
>         tmp = xstrdup(info->author);
>         author = string_list_insert(authors, tmp);
>         if (!author->util)
>                 author->util = xcalloc(1, sizeof(struct authorstat));
>         else
>                 free(tmp);
>         authorstat = author->util;
>         items = &authorstat->list;
>         t = info->committer_date;
>         date = gmtime(&t);
>         period->trunc(date);
>         tmp = xstrdup(period->pretty(date));
>         item = string_list_insert(items, tmp);
>         if (item->util)
>                 free(tmp);
>         item->util++;
>         authorstat->total++;
>         cgit_free_commitinfo(info);
> }
> 
> It doesn't like the "item->util++" line, since "if (item->util)"
> implies that util could be NULL. That line doesn't make much sense to
> me either. Any guesses?

We're using "util" as a counter here, not a pointer.  But it's declared
as "void*" so Coverity doesn't like this.

We could try adding in some casts to uintptr_t but that's pretty
hideous.  Otherwise we need to allocate an unsigned int for the "util"
field or just ignore Coverity.


More information about the CGit mailing list