Skip to content

Commit

Permalink
Don't compute log of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
DL6ER committed Apr 10, 2017
1 parent 032bfc0 commit 992f16b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void *GC_thread(void *val)
{
time_t timestamp = queries[i].timestamp;
logg("GC query with time: %s", strtok(ctime(&timestamp),"\n"));
printf("queries[i = %lu] = {timestamp = %i, timeidx = %i, type = %i, status = %i, domainID = %i, clientID = %i, forwardID = %i, valid = false}\n", i, queries[i].timestamp, queries[i].timeidx, queries[i].type, queries[i].status, queries[i].domainID, queries[i].clientID, queries[i].forwardID);
printf("queries[i = %li] = {timestamp = %i, timeidx = %i, type = %i, status = %i, domainID = %i, clientID = %i, forwardID = %i, valid = false}\n", i, queries[i].timestamp, queries[i].timeidx, queries[i].type, queries[i].status, queries[i].domainID, queries[i].clientID, queries[i].forwardID);
printf("domains[j = %i] = {count = %i, blockedcount = %i, domain = \"%s\", wildcard = %i}\n", queries[i].domainID, domains[queries[i].domainID].count, domains[queries[i].domainID].blockedcount, domains[queries[i].domainID].domain, domains[queries[i].domainID].wildcard);
printf("clients[k = %i] = {count = %i, ip = \"%s\", name = \"%s\"}\n", queries[i].clientID, clients[queries[i].clientID].count, clients[queries[i].clientID].ip, clients[queries[i].clientID].name);
if(queries[i].forwardID > -1)
Expand Down
6 changes: 3 additions & 3 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ void logg(const char *format, ...)

void format_memory_size(char *prefix, unsigned long int bytes, double *formated)
{
int exponent = floor(log10(bytes)/3.);
if(exponent > 0 && exponent < 7)
if(bytes > 0)
{
int exponent = floor(log10(bytes)/3.);
const char* prefixes[7] = { "", "K", "M", "G", "T", "P", "E" };
strcpy(prefix, prefixes[exponent]);
*formated = (double)bytes/pow(10.0,exponent*3.0);
}
else
{
strcpy(prefix, "");
strcpy(prefix, "\'");
*formated = (double)bytes;
}
}
Expand Down

0 comments on commit 992f16b

Please sign in to comment.