reftable/basics: handle allocation failures in parse_names()
Handle allocation failures in `parse_names()` by returning `NULL` in case any allocation fails. While at it, refactor the function to return the array directly instead of assigning it to an out-pointer. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
6593e147d3
commit
eef7bcdafe
@ -72,13 +72,14 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
if_test ("parse_names works for basic input") {
|
||||
char in1[] = "line\n";
|
||||
char in2[] = "a\nb\nc";
|
||||
char **out = NULL;
|
||||
parse_names(in1, strlen(in1), &out);
|
||||
char **out = parse_names(in1, strlen(in1));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "line");
|
||||
check(!out[1]);
|
||||
free_names(out);
|
||||
|
||||
parse_names(in2, strlen(in2), &out);
|
||||
out = parse_names(in2, strlen(in2));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "a");
|
||||
check_str(out[1], "b");
|
||||
check_str(out[2], "c");
|
||||
@ -88,8 +89,8 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
|
||||
if_test ("parse_names drops empty string") {
|
||||
char in[] = "a\n\nb\n";
|
||||
char **out = NULL;
|
||||
parse_names(in, strlen(in), &out);
|
||||
char **out = parse_names(in, strlen(in));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "a");
|
||||
/* simply '\n' should be dropped as empty string */
|
||||
check_str(out[1], "b");
|
||||
|
Reference in New Issue
Block a user