From 02bc7763880f87936c92c171091600b85984d697 Mon Sep 17 00:00:00 2001 From: Christoph Muellner Date: Wed, 26 Jun 2019 14:49:28 +0200 Subject: [PATCH] Fix compilation issue in split_item(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recent compilers complain with the following message: main.cpp: In function ‘void split_item(STRING_VECTOR&, char*)’: main.cpp:2840:10: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length This patch addresses this issue. Signed-off-by: Christoph Muellner --- main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index f09e181..8758769 100644 --- a/main.cpp +++ b/main.cpp @@ -2827,7 +2827,7 @@ void split_item(STRING_VECTOR &vecItems, char *pszItems) pStart = pszItems; pos = strchr(pStart, ','); while(pos != NULL) { - memset(szItem, 0, 100); + memset(szItem, 0, sizeof(szItem)); strncpy(szItem, pStart, pos - pStart); strItem = szItem; vecItems.push_back(strItem); @@ -2837,8 +2837,8 @@ void split_item(STRING_VECTOR &vecItems, char *pszItems) pos = strchr(pStart, ','); } if (strlen(pStart) > 0) { - memset(szItem, 0, 100); - strncpy(szItem, pStart, strlen(pStart)); + memset(szItem, 0, sizeof(szItem)); + strncpy(szItem, pStart, sizeof(szItem)-1); strItem = szItem; vecItems.push_back(strItem); }