cgit

commit a8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd

Author: Jason A. Donenfeld <Jason@zx2c4.com>

ui-stats: if we're going to abuse void*, do it safely

 ui-stats.c | 17 +++++++----------


diff --git a/ui-stats.c b/ui-stats.c
index 74ce0f7197a6597667995be3d7096848c9a68174..a9c13fd4c5e930278ce784960fb85f9234dd0a81 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -3,12 +3,6 @@ #include "ui-stats.h"
 #include "html.h"
 #include "ui-shared.h"
 
-#ifdef NO_C99_FORMAT
-#define SZ_FMT "%u"
-#else
-#define SZ_FMT "%zu"
-#endif
-
 struct authorstat {
 	long total;
 	struct string_list list;
@@ -174,6 +168,7 @@ 	struct string_list *items;
 	char *tmp;
 	struct tm *date;
 	time_t t;
+	uintptr_t *counter;
 
 	info = cgit_parse_commit(commit);
 	tmp = xstrdup(info->author);
@@ -191,7 +186,9 @@ 	tmp = xstrdup(period->pretty(date));
 	item = string_list_insert(items, tmp);
 	if (item->util)
 		free(tmp);
-	item->util++;
+	counter = (uintptr_t *)&item->util;
+	(*counter)++;
+
 	authorstat->total++;
 	cgit_free_commitinfo(info);
 }
@@ -286,7 +283,7 @@ 			authorstat = author->util;
 			items = &authorstat->list;
 			date = string_list_lookup(items, tmp);
 			if (date)
-				subtotal += (size_t)date->util;
+				subtotal += (uintptr_t)date->util;
 		}
 		htmlf("<td class='%s'>%ld</td>", centerclass, subtotal);
 		total += subtotal;
@@ -340,8 +337,8 @@ 			date = string_list_lookup(items, tmp);
 			if (!date)
 				html("<td>0</td>");
 			else {
-				htmlf("<td>"SZ_FMT"</td>", (size_t)date->util);
-				total += (size_t)date->util;
+				htmlf("<td>%lu</td>", (uintptr_t)date->util);
+				total += (uintptr_t)date->util;
 			}
 		}
 		htmlf("<td class='sum'>%ld</td></tr>", total);