]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Unit-tests] Fix test framework error on newer compiler: 'strncpy' output truncated... 2839/head
authorAndrey Volk <andywolk@gmail.com>
Thu, 10 Jul 2025 16:06:01 +0000 (19:06 +0300)
committerAndrey Volk <andywolk@gmail.com>
Thu, 10 Jul 2025 16:15:31 +0000 (19:15 +0300)
src/include/test/switch_fct.h
tests/unit/switch_core.c

index b28feabb742b43f3f420341a396c8ac0353eaaea..91d87bbb9ca50a3a9f8f594c388c88a2abed10eb 100644 (file)
@@ -254,10 +254,18 @@ fctstr_safe_cpy(char *dst, char const *src, size_t num)
     FCT_ASSERT( num > 0 );
 #if defined(WIN32) && _MSC_VER >= 1400
     strncpy_s(dst, num, src, _TRUNCATE);
+    dst[num - 1] = '\0';
 #else
-    strncpy(dst, src, num - 1);
+    {
+        size_t i;
+
+        for (i = 0; (i < num - 1) && src[i] != '\0'; ++i) {
+            dst[i] = src[i];
+        }
+
+        dst[i] = '\0';
+    }
 #endif
-    dst[num-1] = '\0';
 }
 
 /* Isolate the vsnprintf implementation */
index 295e4e0ff159afd9b38c8813fda7e5e72a357189..397fe919caccfec39d842132a43c92ffc900b320 100644 (file)
@@ -53,6 +53,17 @@ FST_CORE_BEGIN("./conf")
                }
                FST_TEARDOWN_END()
 
+               FST_TEST_BEGIN(test_fctstr_safe_cpy)
+               {
+                       char *dst;
+                       const char *src = "1234567890";
+
+                       dst = fctstr_clone(src);
+                       fst_check_string_equals(dst, src);
+                       free(dst);
+               }
+               FST_TEST_END()
+
                FST_TEST_BEGIN(test_switch_rand)
                {
                        int i, c = 0;