aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-15 12:52:29 -0400
committerNick Mathewson <nickm@torproject.org>2013-07-15 12:52:29 -0400
commit9fda7e8cd1bbc33479c667ea97a220333f81c148 (patch)
treef5e48339cf19cac8d7613049b6f934594f0e0fbb /src/test/test_util.c
parent18136afbbb4934c1104716a29a0efc68a8fd8f51 (diff)
downloadtor-9fda7e8cd1bbc33479c667ea97a220333f81c148.tar
tor-9fda7e8cd1bbc33479c667ea97a220333f81c148.tar.gz
Lightly refactor and test format_hex_number_sigsafe
Better tests for upper bounds, and for failing cases. Also, change the function's interface to take a buffer length rather than a maximum length, and then NUL-terminate: functions that don't NUL-terminate are trouble waiting to happen.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4880b73a5..2cc25e986 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2643,7 +2643,8 @@ test_util_format_hex_number(void *ptr)
{"1", 1},
{"273A", 0x273a},
{"FFFF", 0xffff},
-
+ {"7FFFFFFF", 0x7fffffff},
+ {"FFFFFFFF", 0xffffffff},
#if UINT_MAX >= 0xffffffff
{"31BC421D", 0x31bc421d},
{"FFFFFFFF", 0xffffffff},
@@ -2654,18 +2655,23 @@ test_util_format_hex_number(void *ptr)
(void)ptr;
for (i = 0; test_data[i].str != NULL; ++i) {
- len = format_hex_number_sigsafe(test_data[i].x, buf, 32);
+ len = format_hex_number_sigsafe(test_data[i].x, buf, sizeof(buf));
test_neq(len, 0);
- buf[len] = '\0';
+ test_eq(len, strlen(buf));
test_streq(buf, test_data[i].str);
}
+ test_eq(4, format_hex_number_sigsafe(0xffff, buf, 5));
+ test_streq(buf, "FFFF");
+ test_eq(0, format_hex_number_sigsafe(0xffff, buf, 4));
+ test_eq(0, format_hex_number_sigsafe(0, buf, 1));
+
done:
return;
}
/**
- * Test that we can properly format q Windows command line
+ * Test that we can properly format a Windows command line
*/
static void
test_util_join_win_cmdline(void *ptr)