Changed type of some integer variables to avoid overflows

This commit is contained in:
Sebastian Martin Dicke 2018-02-28 19:06:27 +01:00 committed by Hisham Muhammad
parent 6ee99566cd
commit 2e1f56d934
1 changed files with 5 additions and 5 deletions

View File

@ -27,8 +27,8 @@ in the source distribution for its full text.
*/ */
char* String_cat(const char* s1, const char* s2) { char* String_cat(const char* s1, const char* s2) {
int l1 = strlen(s1); size_t l1 = strlen(s1);
int l2 = strlen(s2); size_t l2 = strlen(s2);
char* out = xMalloc(l1 + l2 + 1); char* out = xMalloc(l1 + l2 + 1);
strncpy(out, s1, l1); strncpy(out, s1, l1);
strncpy(out + l1, s2, l2 + 1); strncpy(out + l1, s2, l2 + 1);
@ -39,7 +39,7 @@ char* String_trim(const char* in) {
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
in++; in++;
} }
int len = strlen(in); size_t len = strlen(in);
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
len--; len--;
} }
@ -80,7 +80,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); size_t size = strlen(s);
char* token = xMalloc(size + 1); char* token = xMalloc(size + 1);
strncpy(token, s, size + 1); strncpy(token, s, size + 1);
out[ctr] = token; out[ctr] = token;