umalloc fixes

This commit is contained in:
2025-09-28 19:55:37 +02:00
parent c07a2c957b
commit 96ce9233ff
6 changed files with 105 additions and 70 deletions

View File

@ -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;
}