mirror of https://github.com/xzeldon/htop.git
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:
parent
21fb56e1e2
commit
7457bfe9f3
|
@ -81,10 +81,7 @@ char** String_split(const char* s, char sep, int* n) {
|
||||||
s += size + 1;
|
s += size + 1;
|
||||||
}
|
}
|
||||||
if (s[0] != '\0') {
|
if (s[0] != '\0') {
|
||||||
int size = strlen(s);
|
out[ctr] = xStrdup(s);
|
||||||
char* token = xMalloc(size + 1);
|
|
||||||
strncpy(token, s, size + 1);
|
|
||||||
out[ctr] = token;
|
|
||||||
ctr++;
|
ctr++;
|
||||||
}
|
}
|
||||||
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||||
|
|
Loading…
Reference in New Issue