aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/utils.c b/src/utils.c
index 01969a2..29e8219 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -22,8 +22,6 @@ char * magi_str_create_copy(const char * begin, const char * end)
if (res) {
memcpy(res, begin, end - begin);
res[end - begin] = 0;
- } else {
- magi_error_set("Cannot allocate string.");
}
return res;
}
@@ -33,26 +31,21 @@ char * magi_str_create(int len)
char * str = malloc(len + 1);
if (str) {
str[len] = 0;
- } else {
- magi_error_set("Cannot allocate string.");
}
return str;
}
-int magi_str_add(char ** dest, int * len, int * size, char c)
+char * magi_str_add(char * dest, int * len, int * size, char c)
{
int ok = 1;
if (*len + 1 == *size) {
*size *= 2;
- *dest = realloc(*dest, *size);
+ dest = realloc(dest, *size);
}
- if (*dest == 0) {
- ok = 0;
- magi_error_set("Cannot allocate string.");
- } else {
- (*dest)[*len] = c;
+ if (dest) {
+ dest[*len] = c;
++*len;
- (*dest)[*len] = 0;
+ dest[*len] = 0;
}
- return ok;
+ return dest;
}