all repos — cgit @ bdcbe0922d7099ebd61d875709ea9408bc1d7543

a hyperfast web frontend for git written in c

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>
John Keeping john@keeping.me.uk
Mon, 08 Feb 2016 14:12:35 +0000
commit

bdcbe0922d7099ebd61d875709ea9408bc1d7543

parent

a8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd

1 files changed, 2 insertions(+), 2 deletions(-)

jump to
M ui-stats.cui-stats.c

@@ -184,9 +184,9 @@ date = gmtime(&t);

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++;