diff options
author | Daniel Lange <DLange@git.local> | 2020-08-27 07:48:10 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-08-27 07:48:10 +0200 |
commit | f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4 (patch) | |
tree | 3ee82b2af2ab3d38b6e4b07f3994516aac72f742 /StringUtils.c | |
parent | df568a576f7b44ac5a2b9b7222c7f39d9932f626 (diff) | |
download | debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.gz debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.bz2 debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.zip |
New upstream version 3.0.0upstream/3.0.0
Diffstat (limited to 'StringUtils.c')
-rw-r--r-- | StringUtils.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/StringUtils.c b/StringUtils.c index 0578cde..d7058a2 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -30,8 +30,9 @@ char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); - strncpy(out, s1, l1); - strncpy(out+l1, s2, l2+1); + memcpy(out, s1, l1); + memcpy(out+l1, s2, l2+1); + out[l1 + l2] = '\0'; return out; } @@ -80,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)); @@ -116,7 +114,7 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { if (lastState == 0 && inWord == 1) count++; - + if(inWord == 1){ if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { match[foundCount] = line[i]; |