List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 0/3] Fix some issues found by Coverity
Date: Mon, 8 Feb 2016 14:16:48 +0000	[thread overview]
Message-ID: <20160208141647.GM29880@serenity.lan> (raw)
In-Reply-To: <CAHmME9rB+As-Dkc0ZzNauH2MJom3tt-mTFSTTbRHWCBB3eX9HA@mail.gmail.com>

On Mon, Feb 08, 2016 at 02:35:10PM +0100, Jason A. Donenfeld wrote:
> http://git.zx2c4.com/cgit/commit/?id=a8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd

I'm not sure that quite goes far enough.  Do you want to add this on
top?

-- >8 --
From fad329930c9f57e0d75d9094bc70532283bd2b79 Mon Sep 17 00:00:00 2001
From: John Keeping <john at keeping.me.uk>
Date: Mon, 8 Feb 2016 14:12:35 +0000
Subject: [PATCH] ui-stats: cast pointer before checking for zero

We abuse the "void *util" field as a counter and recently started to
cast it to a uintptr_t to avoid risking nasal demons by performing
arithmetic on a void pointer.

However, compilers are also known to do "interesting" things if they
know that a pointer is or isn't NULL.  Make this safer by checking if
the counter (after casting) is non-zero rather than checking if the
pointer is non-null.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-stats.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui-stats.c b/ui-stats.c
index a9c13fd..8cd9178 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -184,9 +184,9 @@ static void add_commit(struct string_list *authors, struct commit *commit,
 	period->trunc(date);
 	tmp = xstrdup(period->pretty(date));
 	item = string_list_insert(items, tmp);
-	if (item->util)
-		free(tmp);
 	counter = (uintptr_t *)&item->util;
+	if (*counter)
+		free(tmp);
 	(*counter)++;
 
 	authorstat->total++;
-- 
2.7.0.389.ga73dcac



  reply	other threads:[~2016-02-08 14:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-16 11:03 john
2016-01-16 11:03 ` [PATCH 1/3] ui-log: handle parse_commit() errors john
2016-01-16 11:03 ` [PATCH 2/3] cache: use size_t for string lengths john
2016-01-16 11:03 ` [PATCH 3/3] cache: don't check for match with no key john
2016-01-17 16:04 ` [PATCH 0/3] Fix some issues found by Coverity Jason
2016-01-17 16:19   ` Jason
2016-01-17 20:25     ` john
2016-02-03  4:46       ` mathstuf
2016-02-08 13:35         ` Jason
2016-02-08 14:16           ` john [this message]
2016-02-08 14:33             ` Jason
2016-02-08 16:31               ` john
2016-02-08 17:26                 ` Jason

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=20160208141647.GM29880@serenity.lan \
    --to=cgit@lists.zx2c4.com \
    /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).