umalloc fixes
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string/string.h>
|
||||
#include <umalloc/umalloc.h>
|
||||
#include <write/write.h>
|
||||
|
||||
size_t string_len(const char *s) {
|
||||
size_t l = 0;
|
||||
@ -140,26 +141,29 @@ char *string_tokenizealloc(char *s, char *delim) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (s[curridx] && string_strchr(delim, s[curridx])) {
|
||||
curridx++;
|
||||
}
|
||||
if (!s[curridx]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *w = (char *)umalloc(sizeof(char) * STRING_TOKENIZEALLOC_TOK_SIZE);
|
||||
string_memset(w, 0, sizeof(char) * STRING_TOKENIZEALLOC_TOK_SIZE);
|
||||
int i = curridx, k = 0, j = 0;
|
||||
|
||||
while (s[i] != '\0') {
|
||||
j = 0;
|
||||
while (delim[j] != '\0') {
|
||||
if (s[i] != delim[j]) {
|
||||
w[k] = s[i];
|
||||
} else {
|
||||
goto it;
|
||||
}
|
||||
j++;
|
||||
int k = 0;
|
||||
while (s[curridx] && !string_strchr(delim, s[curridx])) {
|
||||
if (k >= STRING_TOKENIZEALLOC_TOK_SIZE - 1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
k++;
|
||||
w[k++] = s[curridx++];
|
||||
}
|
||||
it: {
|
||||
w[i] = 0;
|
||||
curridx = i + 1;
|
||||
return w;
|
||||
|
||||
w[k] = '\0';
|
||||
|
||||
if (s[curridx]) {
|
||||
curridx++;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
Reference in New Issue
Block a user