Jim Meyering wrote:
> +static int
> +print_long_range (int first, int last)
> +{
> + (void) first;
> + int ret;
> + char *cmd;
> + ret = asprintf (&cmd, "yes | head -n%d | cat -n | tr -cd '[0-9\\n]'",
> last);
> + if (ret != -1)
> + ret = system (cmd);
> + free (cmd);
> + return ret;
> +}
Actually getting to a review, there's a minor problem
in freeing "cmd" when asprintf fails. In that case,
cmd is officially "undefined", so we must not free it:
diff --git a/src/seq.c b/src/seq.c
index 212772e..3f9a5fe 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -257,8 +257,10 @@ print_long_range (int first, int last)
char *cmd;
ret = asprintf (&cmd, "yes | head -n%d | cat -n | tr -cd '[0-9\\n]'", last);
if (ret != -1)
- ret = system (cmd);
- free (cmd);
+ {
+ ret = system (cmd);
+ free (cmd);
+ }
return ret;
}