summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-12 17:09:47 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-12 17:09:47 -0400
commitfdcb065bf7b1002a4c5e81b345848f47562938a3 (patch)
treebbf62b0c2ffe763c49c80eb69365a552bc15f05f
parent070e82a02d89f06ab83daa1a3186258f5205dde1 (diff)
parentdedafe95feff363b0dac086e1f034b88dc112952 (diff)
downloadtor-fdcb065bf7b1002a4c5e81b345848f47562938a3.tar.gz
tor-fdcb065bf7b1002a4c5e81b345848f47562938a3.zip
Merge branch 'maint-0.3.0' into release-0.3.0
-rw-r--r--changes/bug155824
-rw-r--r--src/test/test_util.c21
2 files changed, 20 insertions, 5 deletions
diff --git a/changes/bug15582 b/changes/bug15582
new file mode 100644
index 0000000000..5ea6431cf8
--- /dev/null
+++ b/changes/bug15582
@@ -0,0 +1,4 @@
+ o Minor bugfixes (compilation):
+ - Avoid compiler warnings in the unit tests for running tor_sscanf()
+ with wide string outputs. Fixes bug 15582; bugfix on 0.2.6.2-alpha.
+
diff --git a/src/test/test_util.c b/src/test/test_util.c
index e80201737a..ab6fe8ded9 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2518,7 +2518,7 @@ test_util_sscanf(void *arg)
{
unsigned u1, u2, u3;
unsigned long ulng;
- char s1[20], s2[10], s3[10], ch;
+ char s1[20], s2[10], s3[10], ch, *huge = NULL;
int r;
long lng1,lng2;
int int1, int2;
@@ -2530,7 +2530,13 @@ test_util_sscanf(void *arg)
tt_int_op(-1,OP_EQ,
tor_sscanf("wrong", "%5c", s1)); /* %c cannot have a number. */
tt_int_op(-1,OP_EQ, tor_sscanf("hello", "%s", s1)); /* %s needs a number. */
- tt_int_op(-1,OP_EQ, tor_sscanf("prettylongstring", "%999999s", s1));
+ /* this will fail because we don't allow widths longer than 9999 */
+ {
+ huge = tor_malloc(1000000);
+ r = tor_sscanf("prettylongstring", "%99999s", huge);
+ tor_free(huge);
+ tt_int_op(-1,OP_EQ, r);
+ }
#if 0
/* GCC thinks these two are illegal. */
test_eq(-1, tor_sscanf("prettylongstring", "%0s", s1));
@@ -2636,8 +2642,13 @@ test_util_sscanf(void *arg)
tt_int_op(2,OP_EQ, tor_sscanf("76trombones", "%6u%9s", &u1, s1)); /* %u%s */
tt_int_op(76,OP_EQ, u1);
tt_str_op(s1,OP_EQ, "trombones");
- tt_int_op(1,OP_EQ, tor_sscanf("prettylongstring", "%999s", s1));
- tt_str_op(s1,OP_EQ, "prettylongstring");
+ {
+ huge = tor_malloc(1000);
+ r = tor_sscanf("prettylongstring", "%999s", huge);
+ tt_int_op(1,OP_EQ, r);
+ tt_str_op(huge,OP_EQ, "prettylongstring");
+ tor_free(huge);
+ }
/* %s doesn't eat spaces */
tt_int_op(2,OP_EQ, tor_sscanf("hello world", "%9s %9s", s1, s2));
tt_str_op(s1,OP_EQ, "hello");
@@ -2861,7 +2872,7 @@ test_util_sscanf(void *arg)
test_feq(d4, 3.2);
done:
- ;
+ tor_free(huge);
}
#define tt_char_op(a,op,b) tt_assert_op_type(a,op,b,char,"%c")