@@ 83,7 83,7 @@ astr_realloc_append_formatted_from_va_list(char **s,
size_t length_to_append = astr_formatted_length_from_va_list(format, arguments);
if (!length_to_append) return 0;
- size_t original_length = strlen(*s);
+ size_t original_length = *s ? strlen(*s) : 0;
size_t new_size = original_length + length_to_append + sizeof('\0');
char *resized_s = realloc(*s, new_size);
if (!resized_s) return -1;
@@ 26,7 26,7 @@ test_astr_alloc_formatted(void)
static void
-test_astr_alloc_formatted_for_NULL_format(void)
+test_astr_alloc_formatted_for_invalid_format(void)
{
errno = 0;
char *s = astr_alloc_formatted(NULL);
@@ 117,7 117,7 @@ test_astr_formatted_length(void)
static void
-test_astr_formatted_length_for_NULL_format(void)
+test_astr_formatted_length_for_invalid_format(void)
{
errno = 0;
size_t length = astr_formatted_length(NULL);
@@ 157,6 157,20 @@ test_astr_realloc_append_formatted_for_empty_format(void)
static void
test_astr_realloc_append_formatted_for_NULL_string(void)
{
+ char *s = NULL;
+
+ int result = astr_realloc_append_formatted(&s, "bar %i", 42);
+
+ assert(0 == result);
+ assert(s);
+ assert(astr_eq("bar 42", s));
+ free(s);
+}
+
+
+static void
+test_astr_realloc_append_formatted_for_invalid_string_pointer(void)
+{
errno = 0;
int result = astr_realloc_append_formatted(NULL, "foobar");
@@ 166,7 180,7 @@ test_astr_realloc_append_formatted_for_NULL_string(void)
static void
-test_astr_realloc_append_formatted_for_NULL_format(void)
+test_astr_realloc_append_formatted_for_invalid_format(void)
{
char *s = astr_alloc_formatted("foo");
@@ 184,17 198,18 @@ main(int argc, char *argv[])
{
test_astr_alloc_empty();
test_astr_alloc_formatted();
- test_astr_alloc_formatted_for_NULL_format();
+ test_astr_alloc_formatted_for_invalid_format();
test_astr_cmp();
test_astr_empty();
test_astr_eq();
test_astr_eq_for_NULL_string();
test_astr_eq_for_empty_strings();
test_astr_formatted_length();
- test_astr_formatted_length_for_NULL_format();
+ test_astr_formatted_length_for_invalid_format();
test_astr_realloc_append_formatted_for_empty_format();
test_astr_realloc_append_formatted_for_NULL_string();
- test_astr_realloc_append_formatted_for_NULL_format();
+ test_astr_realloc_append_formatted_for_invalid_string_pointer();
+ test_astr_realloc_append_formatted_for_invalid_format();
return EXIT_SUCCESS;
}