Fix string_clear_get_str when stack allocated
If a string_t is stack-allocated, string_clear_get_str would still try to copy it from the NULL heap pointer, resulting in a failed assertion. Copy from the stack instead. Also add a test for this.
This commit is contained in:
1 parent
a905f12915
commit
3ea063d1e0
2 files changed
+8
No files matched your search
@@ -189,6 +189,7 @@ string_clear_get_str(string_t v)
|
||||
char *p = v->ptr;
|
||||
if (stringi_stack_p(v)) {
|
||||
// The string was stack allocated.
|
||||
p = v->u.stack.buffer;
|
||||
// Need to allocate a heap string to return the copy.
|
||||
size_t alloc = string_size(v)+1;
|
||||
char *ptr = M_MEMORY_REALLOC (char, NULL, alloc);
|
||||
|
||||
Reference in new issue
Block a user