From c43947cfb1e6cbd1a4bdf163bec449cde8bdc777 Mon Sep 17 00:00:00 2001 From: yangkunlun Date: Sat, 23 Feb 2019 22:26:27 +0800 Subject: [PATCH] Fixed Build Failed - gcc 8.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ERROR: main.cpp:2841:10: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] Since the allocation is only 100*char, the reasonable fix would be limit the strncpy to only (100-1)*char. --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index f09e181..47d92c0 100644 --- a/main.cpp +++ b/main.cpp @@ -2838,7 +2838,7 @@ void split_item(STRING_VECTOR &vecItems, char *pszItems) } if (strlen(pStart) > 0) { memset(szItem, 0, 100); - strncpy(szItem, pStart, strlen(pStart)); + strncpy(szItem, pStart, 100-1); strItem = szItem; vecItems.push_back(strItem); }