From f9eb53a215f3dec274717a01e634c8aed475fac2 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 9 Jul 2011 23:32:25 +0200 Subject: [PATCH] bug: use uint32_t for IP numbers The commit 1e82461875373748d619acd72791d0af2d2cb621 was incomplete, and at the end was a cause of off by one miscount. The reason was bsearch where long int needed to be unsigned. Weird that the original had work while there where so many type mismatches. Signed-off-by: Sami Kerola --- src/analyze.c | 2 +- src/getdata.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/analyze.c b/src/analyze.c index a636240..77d848c 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -64,7 +64,7 @@ int prepare_data(void) for (i = 0; i < num_touches; i++) { if (bsearch (&touches[i], leases, (size_t) num_leases, - sizeof(long int), &intcomp) == NULL) { + sizeof(uint32_t), &intcomp) == NULL) { touches[j] = touches[i]; j++; } diff --git a/src/getdata.c b/src/getdata.c index 3393d12..bce5ce4 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -113,14 +113,14 @@ int parse_leases(void) leasesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2; touchesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2; backupsmallocsize = (lease_file_stats.st_size / 120) + MAXLEN - 2; - leases = safe_malloc(sizeof(long int) * leasesmallocsize); - touches = safe_malloc((size_t) sizeof(long int) * touchesmallocsize); + leases = safe_malloc(sizeof(uint32_t) * leasesmallocsize); + touches = safe_malloc(sizeof(uint32_t) * touchesmallocsize); - memset(leases, 0, sizeof(long int) * leasesmallocsize); - memset(touches, 0, sizeof(long int) * touchesmallocsize); + memset(leases, 0, sizeof(uint32_t) * leasesmallocsize); + memset(touches, 0, sizeof(uint32_t) * touchesmallocsize); - line = safe_malloc(sizeof(long int) * MAXLEN); - ipstring = safe_malloc(sizeof(long int) * MAXLEN); + line = safe_malloc(sizeof(char) * MAXLEN); + ipstring = safe_malloc(sizeof(char) * MAXLEN); if (config.output_format[0] == 'X') { macstring = safe_malloc(sizeof(char) * 18); macaddr = safe_malloc(sizeof(struct macaddr_t)); @@ -164,7 +164,7 @@ int parse_leases(void) } else if (strstr(line, " binding state backup")) { if (num_backups == 0) { backups = - safe_malloc((size_t) sizeof(long int) * + safe_malloc(sizeof(uint32_t) * backupsmallocsize); } backups[num_backups] = htonl(inp.s_addr);