Fix compilation issue in split_item().

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 <christoph.muellner@theobroma-systems.com>
This commit is contained in:
Christoph Muellner 2019-06-26 14:49:28 +02:00
parent 610bb714ae
commit 02bc776388

View File

@ -2827,7 +2827,7 @@ void split_item(STRING_VECTOR &vecItems, char *pszItems)
pStart = pszItems; pStart = pszItems;
pos = strchr(pStart, ','); pos = strchr(pStart, ',');
while(pos != NULL) { while(pos != NULL) {
memset(szItem, 0, 100); memset(szItem, 0, sizeof(szItem));
strncpy(szItem, pStart, pos - pStart); strncpy(szItem, pStart, pos - pStart);
strItem = szItem; strItem = szItem;
vecItems.push_back(strItem); vecItems.push_back(strItem);
@ -2837,8 +2837,8 @@ void split_item(STRING_VECTOR &vecItems, char *pszItems)
pos = strchr(pStart, ','); pos = strchr(pStart, ',');
} }
if (strlen(pStart) > 0) { if (strlen(pStart) > 0) {
memset(szItem, 0, 100); memset(szItem, 0, sizeof(szItem));
strncpy(szItem, pStart, strlen(pStart)); strncpy(szItem, pStart, sizeof(szItem)-1);
strItem = szItem; strItem = szItem;
vecItems.push_back(strItem); vecItems.push_back(strItem);
} }