test-strxcpyx: add test for strpcpyf overflow
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 2 Jul 2017 16:37:42 +0000 (12:37 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 4 Jul 2017 00:50:14 +0000 (20:50 -0400)
This fails before 'strxcpyx: don't overflow dest on strpcpyf truncate'.

src/test/test-strxcpyx.c

index 9bea770..d95945f 100644 (file)
@@ -51,6 +51,13 @@ static void test_strpcpyf(void) {
 
         assert_se(streq(target, "space left: 25. foobar"));
         assert_se(space_left == 3);
+
+        /* test overflow */
+        s = target;
+        space_left = strpcpyf(&s, 12, "00 left: %i. ", 999);
+        assert_se(streq(target, "00 left: 99"));
+        assert_se(space_left == 0);
+        assert_se(target[12] == '2');
 }
 
 static void test_strpcpyl(void) {