mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 16:38:42 +00:00
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>
This commit is contained in:
parent
a8b9ef8c1c
commit
bdcbe0922d
@ -184,9 +184,9 @@ static void add_commit(struct string_list *authors, struct commit *commit,
|
|||||||
period->trunc(date);
|
period->trunc(date);
|
||||||
tmp = xstrdup(period->pretty(date));
|
tmp = xstrdup(period->pretty(date));
|
||||||
item = string_list_insert(items, tmp);
|
item = string_list_insert(items, tmp);
|
||||||
if (item->util)
|
|
||||||
free(tmp);
|
|
||||||
counter = (uintptr_t *)&item->util;
|
counter = (uintptr_t *)&item->util;
|
||||||
|
if (*counter)
|
||||||
|
free(tmp);
|
||||||
(*counter)++;
|
(*counter)++;
|
||||||
|
|
||||||
authorstat->total++;
|
authorstat->total++;
|
||||||
|
Loading…
Reference in New Issue
Block a user