test/string_tests.c

changeset 272
2def28b65328
parent 259
2f5dea574a75
child 283
c3b6ff227481
--- a/test/string_tests.c	Sun Jan 21 10:14:47 2018 +0100
+++ b/test/string_tests.c	Sun Jan 21 10:57:32 2018 +0100
@@ -193,6 +193,21 @@
     UCX_TEST_ASSERT(t4.length == 0, "t4 has wrong length");
     free(t4.ptr);
     
+    // overflow test
+    sstr_t o0;
+    o0.ptr = "";
+    o0.length = ((size_t)-1) - 50;
+    sstr_t o1;
+    o1.ptr = "";
+    o1.length = 100;
+    sstr_t o2;
+    o2.ptr = "";
+    o2.length = 10;
+    
+    sstr_t n = sstrcat(2, o0, o1);
+    UCX_TEST_ASSERT(n.ptr == NULL && n.length == 0, "overflow not detected");
+    sstr_t n2 = sstrcat(3, o0, o2, o1);
+    UCX_TEST_ASSERT(n2.ptr == NULL && n2.length == 0, "n2: overflow not detected");
             
     UCX_TEST_END
     

mercurial