[BusyBox] [PATCH] - Bug fix, seq endless loop

Felipe Kellermann stdfk at terra.com.br
Fri Jul 23 05:53:55 UTC 2004


Package: busybox
Version: v1.00-rc1 (2004.07.22-02:18+0000)
Severity: bug fix

This is just to conform to GNU' seq.  Busybox' seq is doing an "endless" 
loop when first > last and increment > 0.  Recently the coreutils people 
decided to not default the `step' to -1 when we have `first > last'.  So 
when he have these values we should print nothing, as increment defaults 
to 1:

$ seq --version | head -1 && seq 9 1
seq (coreutils) 5.2.0
$

Our current seq behavior:  An endless loop.  This patch fixes that.  And 
adds some code to conform to `style-guide', adds modeline and comments.

-- 
Felipe Kellermann
-------------- next part --------------
Index: coreutils/seq.c
===================================================================
RCS file: /var/cvs/busybox/coreutils/seq.c,v
retrieving revision 1.2
diff -u -3 -p -b -w -u -r1.2 seq.c
--- coreutils/seq.c	4 Feb 2004 11:01:19 -0000	1.2
+++ coreutils/seq.c	23 Jul 2004 05:50:05 -0000
@@ -1,4 +1,7 @@
+/* vi: set sw=4 ts=4: */
 /*
+ * seq implementation for busybox
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of version 2 of the GNU General Public License as
  *  published by the Free Software Foundation.
@@ -27,18 +30,22 @@ extern int seq_main(int argc, char **arg
 	if (argc == 4) {
 		first = atof(argv[1]);
 		increment = atof(argv[2]);
-	}
-	else if (argc == 3) {
+	} else if (argc == 3) {
 		first = atof(argv[1]);
-	}
-	else if (argc != 2) {
+	} else if (argc != 2) {
 		bb_show_usage();
 	}
 	last = atof(argv[argc - 1]);
 
-	for (i = first; ((first <= last) ? (i <= last): (i >= last));i += increment) {
+	/* You should note that this is pos-5.0.91 semantics, -- FK. */
+	if ((first > last) && (increment > 0)) {
+		return EXIT_SUCCESS;
+	}
+
+	for (i = first; ((first <= last) ? (i <= last) : (i >= last));
+	     i += increment) {
 		printf("%g\n", i);
 	}
 
-	return(EXIT_SUCCESS);
+	return EXIT_SUCCESS;
 }


More information about the busybox mailing list