summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-04-10 14:33:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-04-10 14:33:20 +0200
commit9bc2b6e88474a8ebb50c94f29320d343bd374928 (patch)
tree0af73191b3842822d9d1bf7e8729ea49a4df1a2d /coreutils
parenta26711a2d1464167be4ebc990fe21a3809a2da34 (diff)
downloadbusybox-9bc2b6e88474a8ebb50c94f29320d343bd374928.tar.gz
seq: accept negative parameters
function old new delta seq_main 429 476 +47 packed_usage 34557 34538 -19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 47/-19) Total: 28 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/seq.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/coreutils/seq.c b/coreutils/seq.c
index beb339d1e..c0e2d1e06 100644
--- a/coreutils/seq.c
+++ b/coreutils/seq.c
@@ -22,7 +22,7 @@
//usage:#define seq_full_usage "\n\n"
//usage: "Print numbers from FIRST to LAST, in steps of INC.\n"
//usage: "FIRST, INC default to 1.\n"
-//usage: "\n -w Pad to last with leading zeros"
+//usage: "\n -w Pad with leading zeros"
//usage: "\n -s SEP String separator"
#include "libbb.h"
@@ -41,6 +41,7 @@ int seq_main(int argc, char **argv)
unsigned width;
unsigned frac_part;
const char *sep, *opt_s = "\n";
+ char *saved;
unsigned opt;
#if ENABLE_LOCALE_SUPPORT
@@ -49,7 +50,25 @@ int seq_main(int argc, char **argv)
setlocale(LC_NUMERIC, "C");
#endif
- opt = getopt32(argv, "+ws:", &opt_s);
+ /* Cater for negative arguments: if we see one, truncate argv[] on it */
+ n = 0;
+ for (;;) {
+ char c;
+ saved = argv[++n];
+ if (!saved)
+ break;
+ if (saved[0] != '-')
+ break;
+ c = saved[1];
+ if (c == '.' || (c >= '0' && c <= '9')) {
+ argv[n] = NULL;
+ break;
+ }
+ }
+ opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */
+ /* Restore possibly truncated argv[] */
+ argv[n] = saved;
+
argc -= optind;
argv += optind;
first = increment = 1;