]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add two small tests for tor_sscanf
authorEsteban Manchado Velázquez <emanchado@demiurgo.org>
Mon, 20 Feb 2012 16:00:16 +0000 (17:00 +0100)
committerNick Mathewson <nickm@torproject.org>
Fri, 9 Mar 2012 02:16:45 +0000 (21:16 -0500)
src/test/test_util.c

index 7625e2f5def12533b5e7910a532550c0faf5a615..6c14718454b62b4cf0bb431664f807df976e51c9 100644 (file)
@@ -1288,6 +1288,11 @@ test_util_sscanf(void)
   /* No '%'-strings: always "success" */
   test_eq(0, tor_sscanf("hello world", "hello world"));
   test_eq(0, tor_sscanf("hello world", "good bye"));
+  /* Excess data */
+  test_eq(0, tor_sscanf("hello 3", "%u", &u1));  /* have to match the start */
+  test_eq(0, tor_sscanf(" 3 hello", "%u", &u1));
+  test_eq(0, tor_sscanf(" 3 hello", "%2u", &u1)); /* not even in this case */
+  test_eq(1, tor_sscanf("3 hello", "%u", &u1));  /* but trailing is alright */
 
   /* Numbers (ie. %u) */
   test_eq(0, tor_sscanf("hello world 3", "hello worlb %u", &u1)); /* d vs b */