another attempt at fixing empty strings

This commit is contained in:
gilteixeira 2023-03-11 16:51:38 +00:00
parent b5f772324e
commit 16b70f92da
1 changed files with 3 additions and 6 deletions

View File

@ -23,10 +23,9 @@
static UTF8String_t *create_utf8_from_string(const char* string, size_t length) {
UTF8String_t *utf8_string = calloc(1, sizeof(UTF8String_t));
utf8_string->buf = calloc(length + 1, sizeof(uint8_t));
utf8_string->size = length + 1;
utf8_string->buf = calloc(length, sizeof(uint8_t));
utf8_string->size = length;
memcpy(utf8_string->buf, string, length);
utf8_string->buf[length] = '\0';
return utf8_string;
}
@ -34,9 +33,7 @@ static UTF8String_t *create_utf8_from_string(const char* string, size_t length)
static UTF8String_t *create_empty_utf8_string()
{
UTF8String_t *utf8_string = calloc(1, sizeof(UTF8String_t));
utf8_string->buf = calloc(1, 1);
utf8_string->size = 1;
utf8_string->buf[0] = '\0';
utf8_string->size = 0;
return utf8_string;
}