From cced3e7f1bec9058ce8bbd63f27bcb6e7b3fb992 Mon Sep 17 00:00:00 2001
From: Andrey Volk <andywolk@gmail.com>
Date: Mon, 24 Jul 2023 16:20:20 +0300
Subject: [PATCH] [Unit-tests] Fix possible overflows and an undefined variable
 in the test framework.

---
 src/include/test/switch_fct.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/include/test/switch_fct.h b/src/include/test/switch_fct.h
index 8cb07cc20f..b28feabb74 100644
--- a/src/include/test/switch_fct.h
+++ b/src/include/test/switch_fct.h
@@ -255,7 +255,7 @@ fctstr_safe_cpy(char *dst, char const *src, size_t num)
 #if defined(WIN32) && _MSC_VER >= 1400
     strncpy_s(dst, num, src, _TRUNCATE);
 #else
-    strncpy(dst, src, num);
+    strncpy(dst, src, num - 1);
 #endif
     dst[num-1] = '\0';
 }
@@ -760,6 +760,7 @@ fct_nlist__init2(fct_nlist_t *list, size_t start_sz)
         list->itm_list = (void**)malloc(sizeof(void*)*start_sz);
         if ( list->itm_list == NULL )
         {
+            list->used_itm_num = 0;
             return 0;
         }
     }