aboutsummaryrefslogtreecommitdiffstats
path: root/ui-stats.c
diff options
context:
space:
mode:
authorJohn Keeping2016-02-08 14:12:35 +0000
committerJason A. Donenfeld2016-02-08 18:27:38 +0100
commitbdcbe0922d7099ebd61d875709ea9408bc1d7543 (patch)
treedf225a74a832eb528e0686d6286bd8a5282eb633 /ui-stats.c
parenta8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd (diff)
downloadcgit-bdcbe0922d7099ebd61d875709ea9408bc1d7543.tar.gz
cgit-bdcbe0922d7099ebd61d875709ea9408bc1d7543.tar.bz2
cgit-bdcbe0922d7099ebd61d875709ea9408bc1d7543.zip
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@keeping.me.uk>
Diffstat (limited to 'ui-stats.c')
-rw-r--r--ui-stats.c4
1 files 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,
184 period->trunc(date); 184 period->trunc(date);
185 tmp = xstrdup(period->pretty(date)); 185 tmp = xstrdup(period->pretty(date));
186 item = string_list_insert(items, tmp); 186 item = string_list_insert(items, tmp);
187 if (item->util)
188 free(tmp);
189 counter = (uintptr_t *)&item->util; 187 counter = (uintptr_t *)&item->util;
188 if (*counter)
189 free(tmp);
190 (*counter)++; 190 (*counter)++;
191 191
192 authorstat->total++; 192 authorstat->total++;