Skip to content

Commit

Permalink
silence implicit conversions and overflows found by ubsan
Browse files Browse the repository at this point in the history
src/parser.c:530:16: runtime error: implicit conversion from type 'int' of value 232 (32-bit, signed) to type 'char' changed the value to -24 (8-bit, signed)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/parser.c:530:16 in

src/parser.c:1620:19: runtime error: unsigned integer overflow: 1 - 10 cannot be represented in type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/parser.c:1620:19 in

src/parser.c:1606:17: runtime error: unsigned integer overflow: 1 - 10 cannot be represented in type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/parser.c:1606:17 in

src/settings.c:353:12: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'size_t' (aka 'unsigned long') changed the value to 18446744073709551615 (64-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/settings.c:353:12 in

src/util.c:194:13: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/util.c:194:13 in
  • Loading branch information
cgzones committed Nov 15, 2019
1 parent 947bd02 commit 9b9fb33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ decode_hex (char *url, char *out)
if (*c != '%' || !isxdigit (c[1]) || !isxdigit (c[2])) {
*ptr++ = *c;
} else {
*ptr++ = (B16210 (c[1]) * 16) + (B16210 (c[2]));
*ptr++ = (char)((B16210 (c[1]) * 16) + (B16210 (c[2])));
c += 2;
}
}
Expand Down Expand Up @@ -1603,7 +1603,10 @@ count_invalid (GLog * glog, const char *line)
static void
uncount_invalid (GLog * glog)
{
glog->invalid -= conf.num_tests;
if (glog->invalid > conf.num_tests)
glog->invalid -= conf.num_tests;
else
glog->invalid = 0;
#ifdef TCB_BTREE
ht_replace_genstats ("failed_requests", glog->invalid);
#endif
Expand All @@ -1617,7 +1620,10 @@ uncount_invalid (GLog * glog)
static void
uncount_processed (GLog * glog)
{
glog->processed -= conf.num_tests;
if (glog->processed > conf.num_tests)
glog->processed -= conf.num_tests;
else
glog->processed = 0;
#ifdef TCB_BTREE
ht_replace_genstats ("total_requests", glog->processed);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ size_t
get_selected_format_idx (void)
{
if (conf.log_format == NULL)
return -1;
return (size_t)-1;
if (strcmp (conf.log_format, logs.common) == 0)
return COMMON;
else if (strcmp (conf.log_format, logs.vcommon) == 0)
Expand All @@ -372,7 +372,7 @@ get_selected_format_idx (void)
else if (strcmp (conf.log_format, logs.awss3) == 0)
return AWSS3;
else
return -1;
return (size_t)-1;
}

/* Determine the selected log format from the config file or command line
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ genstr (char *dest, size_t len)
{
char set[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

while (len-- > 0)
for (; len > 0; --len)
*dest++ = set[rand () % (sizeof (set) - 1)];
*dest = '\0';
}
Expand Down

0 comments on commit 9b9fb33

Please sign in to comment.