diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-04-03 12:06:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-04-03 12:06:07 -0400 |
commit | b8e582255e8ee920904c71ed9d4ff3927f22757a (patch) | |
tree | 421db363b6c70a8d0335eeed38a0db598c2e39e2 /src | |
parent | 6a9e693fbe5fc7c418e1c187b34a1496b62544cc (diff) | |
parent | b80728a115213abfaab6b3a124caac617ce5d253 (diff) | |
download | tor-b8e582255e8ee920904c71ed9d4ff3927f22757a.tar.gz tor-b8e582255e8ee920904c71ed9d4ff3927f22757a.zip |
Merge remote-tracking branch 'asn-mytor/bug5558_take2'
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 2 | ||||
-rw-r--r-- | src/test/test_util.c | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c index 266368cc9d..551ee1796f 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2773,7 +2773,7 @@ tor_vsscanf(const char *buf, const char *pattern, va_list ap) ++n_matched; } else if (*pattern == '%') { if (*buf != '%') - return -1; + return n_matched; ++buf; ++pattern; } else { diff --git a/src/test/test_util.c b/src/test/test_util.c index 88f00e071b..f2123c5540 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1384,7 +1384,6 @@ test_util_sscanf(void) test_eq(-1, tor_sscanf("wrong", "%5c", s1)); /* %c cannot have a number. */ test_eq(-1, tor_sscanf("hello", "%s", s1)); /* %s needs a number. */ test_eq(-1, tor_sscanf("prettylongstring", "%999999s", s1)); - test_eq(-1, tor_sscanf("We're the 99 monkeys", "We're the 99%%")); #if 0 /* GCC thinks these two are illegal. */ test_eq(-1, tor_sscanf("prettylongstring", "%0s", s1)); @@ -1468,6 +1467,11 @@ test_util_sscanf(void) /* Literal '%' (ie. '%%') */ test_eq(1, tor_sscanf("99% fresh", "%3u%% fresh", &u1)); test_eq(99, u1); + test_eq(0, tor_sscanf("99 fresh", "%% %3u %s", &u1, s1)); + test_eq(1, tor_sscanf("99 fresh", "%3u%% %s", &u1, s1)); + test_eq(2, tor_sscanf("99 fresh", "%3u %5s %%", &u1, s1)); + test_eq(99, u1); + test_streq(s1, "fresh"); test_eq(1, tor_sscanf("% boo", "%% %3s", s1)); test_streq("boo", s1); |