Skip to content

Commit cf3f0f9

Browse files
committed
seq: Fix handling of 0's and invalid numbers
Also added some corresponding testcases.
1 parent 077e948 commit cf3f0f9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/seq.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
set -eux
44

55
set -- \
6+
'0' \
7+
'0 0' \
8+
'0 0 0' \
69
'10' \
710
'5 10' \
811
'0 2 10' \

userland/utilities/seq.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def arg_to_decimal(arg: str) -> Decimal:
5959
exponent: int
6060

6161
if len(args) == 1:
62+
last = arg_to_decimal(args[0])
63+
if not last:
64+
return 0
65+
6266
first = Decimal(1)
6367
increment = Decimal(1)
64-
last = arg_to_decimal(args[0])
6568
exponent = 0
6669
elif len(args) == 2:
6770
first = arg_to_decimal(args[0])
@@ -81,6 +84,9 @@ def arg_to_decimal(arg: str) -> Decimal:
8184
else increment
8285
)
8386

87+
if not increment:
88+
parser.error(f"invalid zero increment value: '{increment}'")
89+
8490
formatstr: str
8591

8692
if opts.equal_width:

0 commit comments

Comments
 (0)