summaryrefslogtreecommitdiffstats
path: root/StringUtils.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-08-20 21:34:28 +0200
committerChristian Göttsche <cgzones@googlemail.com>2020-08-25 11:59:59 +0200
commit7457bfe9f319d939f9840a79703991d4b7beaaab (patch)
tree798308549b9a8877c12167c74a24c621dfe8461b /StringUtils.c
parent21fb56e1e297c5ea85d685eb3809f1052d6f9a7a (diff)
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); | ^
Diffstat (limited to 'StringUtils.c')
-rw-r--r--StringUtils.c5
1 files changed, 1 insertions, 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));

© 2014-2024 Faster IT GmbH | imprint | privacy policy