OpenBSD RCSID merge, and logical follow one change:

handle unknown bases as ksh93 does: larger downgrade to 10
(although our max will stay 36, as ksh93 doesn’t have upper/lowecase)
and smaller downgrade for typeset -i, but not for arithmetics
This commit is contained in:
tg 2014-12-15 23:18:47 +00:00
parent dcdc828c41
commit 5650b03590
3 changed files with 20 additions and 18 deletions

17
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.672 2014/12/15 22:50:08 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.673 2014/12/15 23:18:44 tg Exp $
# OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -4454,11 +4454,11 @@ expected-stdout:
---
name: integer-base-check-numeric-from
description:
Check behaviour for base one to 36, and that 37 errors out
Check behaviour for base one to 36, and that 37 degrades to 10
stdin:
echo 1:$((1#1))0.
i=1
while (( ++i <= 36 )); do
while (( ++i <= 37 )); do
eval 'echo '$i':$(('$i'#10)).'
done
echo 37:$($__progname -c 'echo $((37#10))').$?:
@ -4499,13 +4499,12 @@ expected-stdout:
34:34.
35:35.
36:36.
37:.0:
expected-stderr-pattern:
/.*bad number '37#10'/
37:10.
37:10.0:
---
name: integer-base-check-numeric-to
description:
Check behaviour for base one to 36, and that 37 errors out
Check behaviour for base one to 36, and that 37 degrades to 10
stdin:
i=0
while (( ++i <= 37 )); do
@ -4550,9 +4549,7 @@ expected-stdout:
34:34#1U.64.
35:35#1T.64.
36:36#1S.64.
37:36#1S.64.
expected-stderr-pattern:
/.*bad integer base: 37/
37:64.64.
---
name: integer-arithmetic-span
description:

12
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.261 2014/11/25 21:13:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.262 2014/12/15 23:18:47 tg Exp $");
#if HAVE_KILLPG
/*
@ -768,9 +768,13 @@ c_typeset(const char **wp)
if (fieldstr && !bi_getn(fieldstr, &field))
return (1);
if (basestr && (!bi_getn(basestr, &base) || base < 1 || base > 36)) {
bi_errorf("%s: %s", "bad integer base", basestr);
return (1);
if (basestr) {
if (!bi_getn(basestr, &base)) {
bi_errorf("%s: %s", "bad integer base", basestr);
return (1);
}
if (base < 1 || base > 36)
base = 10;
}
if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind] &&

9
var.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: var.c,v 1.38 2013/12/20 17:53:09 zhuk Exp $ */
/* $OpenBSD: var.c,v 1.40 2014/12/12 05:00:55 jsg Exp $ */
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.184 2014/11/25 21:13:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.185 2014/12/15 23:18:47 tg Exp $");
/*-
* Variables
@ -513,7 +513,7 @@ getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
neg = true;
continue;
} else if (c == '#') {
if (have_base || num < 1 || num > 36)
if (have_base || num < 1)
return (-1);
if ((base = num) == 1) {
unsigned int wc;
@ -530,7 +530,8 @@ getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
wc = 0xEF00 + *(const unsigned char *)s;
nump->u = (mksh_uari_t)wc;
return (1);
}
} else if (base > 36)
base = 10;
num = 0;
have_base = true;
continue;