Clean up some needless malloc casts, convert some mallocs to callocs, and fix some style

This commit is contained in:
Michael McConville
2015-09-16 23:42:36 -04:00
parent 1d805b36b4
commit 445222e48c
8 changed files with 20 additions and 28 deletions

View File

@ -55,13 +55,13 @@ inline int String_eq(const char* s1, const char* s2) {
char** String_split(const char* s, char sep, int* n) {
*n = 0;
const int rate = 10;
char** out = (char**) malloc(sizeof(char*) * rate);
char** out = calloc(rate, sizeof(char**));
int ctr = 0;
int blocks = rate;
char* where;
while ((where = strchr(s, sep)) != NULL) {
int size = where - s;
char* token = (char*) malloc(size + 1);
char* token = malloc(size + 1);
strncpy(token, s, size);
token[size] = '\0';
out[ctr] = token;
@ -80,7 +80,7 @@ char** String_split(const char* s, char sep, int* n) {
}
if (s[0] != '\0') {
int size = strlen(s);
char* token = (char*) malloc(size + 1);
char* token = malloc(size + 1);
strncpy(token, s, size + 1);
out[ctr] = token;
ctr++;