Merge pull request #48 from taboege/string-clear-get-str-stack

Fix string_clear_get_str when stack allocated
This commit is contained in:
PpHd authored and GitHub committed 2019-09-26 07:19:14 +02:00
commit 08842811e8
2 files changed
+8

No files matched your search

+1
View File
@@ -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);
+7
View File
@@ -355,6 +355,13 @@ static void test0(void)
char *s = string_clear_get_str (s1);
assert(strcmp(s, "QWERTYQWERTY") == 0);
free(s);
string_t s3;
string_init(s3);
string_cat_str(s3, "ABC");
s = string_clear_get_str(s3);
assert(strcmp(s, "ABC") == 0);
free(s);
string_init_set_str(s1, "RESTART");
assert (string_equal_str_p(s1, "RESTART"));