coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] seq: speed up the common case by 25x


From: Jim Meyering
Subject: Re: [PATCH] seq: speed up the common case by 25x
Date: Fri, 01 Apr 2011 11:38:47 +0200

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;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]