From 298ec0f626e10680f9f3dc4e229c16618f2c0fa3 Mon Sep 17 00:00:00 2001 From: Andy C Date: Mon, 28 Oct 2024 12:33:22 -0400 Subject: [PATCH] [spec/builtin-printf] Specify that integer overflow is an error Also check for overflow in 'trap'. It's already done to an extent in 'ulimit'. This is part of #2107. --- builtin/trap_osh.py | 6 +++++- spec/builtin-printf.test.sh | 12 +++++++++++- test/runtime-errors.sh | 11 ++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/builtin/trap_osh.py b/builtin/trap_osh.py index 92235e096..ac4bb54b2 100644 --- a/builtin/trap_osh.py +++ b/builtin/trap_osh.py @@ -160,8 +160,12 @@ def _IsUnsignedInteger(s): # Note: could simplify this by making match.LooksLikeUnsigned() + ok, big_int = mops.FromStr2(s) + if not ok: + raise error.Usage('integer too big: %s' % s, loc.Missing) + # not (0 > s) is (s >= 0) - return not mops.Greater(mops.ZERO, mops.FromStr(s)) + return not mops.Greater(mops.ZERO, big_int) def _GetSignalNumber(sig_spec): diff --git a/spec/builtin-printf.test.sh b/spec/builtin-printf.test.sh index 617db7584..611ddf0a4 100644 --- a/spec/builtin-printf.test.sh +++ b/spec/builtin-printf.test.sh @@ -1,4 +1,4 @@ -## oils_failures_allowed: 2 +## oils_failures_allowed: 0 ## compare_shells: dash bash mksh zsh ash # printf @@ -1121,9 +1121,12 @@ for fmt in '%u\n' '%d\n'; do printf "$fmt" '18446744073709551616' echo done + +## status: 1 ## STDOUT: ## END +## OK bash/dash/mksh status: 0 ## OK bash/dash/mksh STDOUT: 18446744073709551615 18446744073709551615 @@ -1133,6 +1136,7 @@ done ## END +## BUG ash status: 0 ## BUG ash STDOUT: 18446744073709551615 0 @@ -1142,6 +1146,7 @@ done ## END +## BUG zsh status: 0 ## BUG zsh STDOUT: 1844674407370955161 1844674407370955161 @@ -1165,9 +1170,12 @@ for fmt in '%u\n' '%d\n'; do printf "$fmt" '-18446744073709551616' echo done + +## status: 1 ## STDOUT: ## END +## OK bash/dash/mksh status: 0 ## OK bash/dash/mksh STDOUT: 1 18446744073709551615 @@ -1177,6 +1185,7 @@ done ## END +## BUG zsh status: 0 ## BUG zsh STDOUT: 16602069666338596455 16602069666338596455 @@ -1186,6 +1195,7 @@ done ## END +## BUG ash status: 0 ## BUG ash STDOUT: 0 0 diff --git a/test/runtime-errors.sh b/test/runtime-errors.sh index e6a8bb406..731241610 100755 --- a/test/runtime-errors.sh +++ b/test/runtime-errors.sh @@ -1204,14 +1204,11 @@ test-int-overflow() { _osh-error-1 'printf %d'" $pos" _osh-error-1 'printf %d'" $neg" - # TODO - return - - _osh-error-1 "trap $pos ERR" - _osh-error-1 "trap $neg ERR" + _osh-error-2 "trap $pos ERR" + _osh-error-2 "trap $neg ERR" - _osh-error-1 "ulimit $pos" - _osh-error-1 "ulimit $neg" + _osh-error-2 "ulimit $pos" + _osh-error-2 "ulimit $neg" } #