shared/shell: Return NULL if generator error occur
Explicitly returns NULL if asprintf() fails, since the asprintf(3)
man-page says that the contents of the first argument are undefined if
any error occurs.
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 0a05b52..7417e7a 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -643,8 +643,13 @@
}
cmd = find_cmd(text + strlen(menu->name) + 1, menu->entries, &index);
- if (cmd)
- asprintf(&cmd, "%s.%s", menu->name, cmd);
+ if (cmd) {
+ int err;
+
+ err = asprintf(&cmd, "%s.%s", menu->name, cmd);
+ if (err < 0)
+ return NULL;
+ }
return cmd;
}