From 7457bfe9f319d939f9840a79703991d4b7beaaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Aug 2020 21:34:28 +0200 Subject: Avoid string overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use xStrdup instead of xMallow and strncpy StringUtils.c: In function ‘String_split’: StringUtils.c:86:7: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 86 | strncpy(token, s, size + 1); | ^ StringUtils.c:84:18: note: length computed here 84 | int size = strlen(s); | ^ --- StringUtils.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/StringUtils.c b/StringUtils.c index 0ac54b12..d7058a28 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -81,10 +81,7 @@ char** String_split(const char* s, char sep, int* n) { s += size + 1; } if (s[0] != '\0') { - int size = strlen(s); - char* token = xMalloc(size + 1); - strncpy(token, s, size + 1); - out[ctr] = token; + out[ctr] = xStrdup(s); ctr++; } out = xRealloc(out, sizeof(char*) * (ctr + 1)); -- cgit v1.2.3