The return value for zero-size allocations is implementation-defined
(can be NULL or a unique pointer for free()). Just return early here as
there is nothing to print.
Caught by Clang static analyzer.
---
sh/hivexsh.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sh/hivexsh.c b/sh/hivexsh.c
index f578ccc..243682c 100644
--- a/sh/hivexsh.c
+++ b/sh/hivexsh.c
@@ -622,6 +622,10 @@ cmd_ls (char *args)
for (len = 0; children[len] != 0; ++len)
;
+ /* No children, no need to print anything. */
+ if (len == 0)
+ return 0;
+
char **names = calloc (len, sizeof (char *));
if (names == NULL) {
perror ("malloc");
--
2.0.2