Avoid string overflow warning

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);
          |                  ^
This commit is contained in:
Christian Göttsche 2020-08-20 21:34:28 +02:00
parent 21fb56e1e2
commit 7457bfe9f3
1 changed files with 1 additions and 4 deletions

View File

@ -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));