one can’t cast an unsigned int to a signed int portably either, if the value
is larger than the positive range of the latter (implementation-defined), so avoid them in all explicit cases and rearrange stuff and check for it (I’m gonna have to revise lots more code…)
This commit is contained in:
parent
fb3555d7f5
commit
7cce9de0bc
10
check.t
10
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.604 2013/04/01 01:16:34 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.605 2013/04/01 02:37:47 tg Exp $
|
||||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
@ -29,7 +29,7 @@
|
|||||||
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
|
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
|
||||||
|
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R44 2013/03/30
|
@(#)MIRBSD KSH R44 2013/03/31
|
||||||
description:
|
description:
|
||||||
Check version of shell.
|
Check version of shell.
|
||||||
stdin:
|
stdin:
|
||||||
@ -38,7 +38,7 @@ name: KSH_VERSION
|
|||||||
category: shell:legacy-no
|
category: shell:legacy-no
|
||||||
---
|
---
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)LEGACY KSH R44 2013/03/30
|
@(#)LEGACY KSH R44 2013/03/31
|
||||||
description:
|
description:
|
||||||
Check version of legacy shell.
|
Check version of legacy shell.
|
||||||
stdin:
|
stdin:
|
||||||
@ -389,6 +389,9 @@ stdin:
|
|||||||
(( sari = -5 >> 1 ))
|
(( sari = -5 >> 1 ))
|
||||||
((# uari = -5 >> 1 ))
|
((# uari = -5 >> 1 ))
|
||||||
print -r -- $((x++)):$sari=$uari. #8
|
print -r -- $((x++)):$sari=$uari. #8
|
||||||
|
(( sari = -2 ))
|
||||||
|
((# uari = sari ))
|
||||||
|
print -r -- $((x++)):$sari=$uari. #9
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
0:0=0.
|
0:0=0.
|
||||||
1:-1=4294967295.
|
1:-1=4294967295.
|
||||||
@ -399,6 +402,7 @@ expected-stdout:
|
|||||||
6:-2147483648=2147483648.
|
6:-2147483648=2147483648.
|
||||||
7:2147483647=2147483647.
|
7:2147483647=2147483647.
|
||||||
8:-3=2147483645.
|
8:-3=2147483645.
|
||||||
|
9:-2=4294967294.
|
||||||
---
|
---
|
||||||
name: arith-unsigned-1
|
name: arith-unsigned-1
|
||||||
description:
|
description:
|
||||||
|
4
expr.c
4
expr.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.67 2013/04/01 02:28:35 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.68 2013/04/01 02:37:49 tg Exp $");
|
||||||
|
|
||||||
#if !HAVE_SILENT_IDIVWRAPV
|
#if !HAVE_SILENT_IDIVWRAPV
|
||||||
#if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
|
#if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
|
||||||
@ -558,7 +558,7 @@ evalexpr(Expr_state *es, int prec)
|
|||||||
if (vasn->flag & INTEGER)
|
if (vasn->flag & INTEGER)
|
||||||
setint_v(vasn, vr, es->arith);
|
setint_v(vasn, vr, es->arith);
|
||||||
else
|
else
|
||||||
setint(vasn, (mksh_ari_t)res);
|
setint(vasn, vr->val.i);
|
||||||
}
|
}
|
||||||
vl = vr;
|
vl = vr;
|
||||||
} else
|
} else
|
||||||
|
4
jobs.c
4
jobs.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.94 2012/12/28 02:28:36 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.95 2013/04/01 02:37:50 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
#define mksh_killpg killpg
|
#define mksh_killpg killpg
|
||||||
@ -463,7 +463,7 @@ exchild(struct op *t, int flags,
|
|||||||
forksleep <<= 1;
|
forksleep <<= 1;
|
||||||
}
|
}
|
||||||
/* ensure $RANDOM changes between parent and child */
|
/* ensure $RANDOM changes between parent and child */
|
||||||
rndset((long)cldpid);
|
rndset((unsigned long)cldpid);
|
||||||
/* fork failed? */
|
/* fork failed? */
|
||||||
if (cldpid < 0) {
|
if (cldpid < 0) {
|
||||||
kill_job(j, SIGKILL);
|
kill_job(j, SIGKILL);
|
||||||
|
4
misc.c
4
misc.c
@ -30,7 +30,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.207 2013/02/24 14:22:43 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.208 2013/04/01 02:37:51 tg Exp $");
|
||||||
|
|
||||||
#define KSH_CHVT_FLAG
|
#define KSH_CHVT_FLAG
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
@ -1979,7 +1979,7 @@ chvt(const char *fn)
|
|||||||
NZATInit(h);
|
NZATInit(h);
|
||||||
NZATUpdateMem(h, &rndsetupstate, sizeof(rndsetupstate));
|
NZATUpdateMem(h, &rndsetupstate, sizeof(rndsetupstate));
|
||||||
NZAATFinish(h);
|
NZAATFinish(h);
|
||||||
rndset((long)h);
|
rndset((unsigned long)h);
|
||||||
}
|
}
|
||||||
chvt_reinit();
|
chvt_reinit();
|
||||||
}
|
}
|
||||||
|
14
sh.h
14
sh.h
@ -164,9 +164,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.646 2013/03/30 23:31:04 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.647 2013/04/01 02:37:51 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R44 2013/03/30"
|
#define MKSH_VERSION "R44 2013/03/31"
|
||||||
|
|
||||||
/* arithmetic types: C implementation */
|
/* arithmetic types: C implementation */
|
||||||
#if !HAVE_CAN_INTTYPES
|
#if !HAVE_CAN_INTTYPES
|
||||||
@ -471,6 +471,14 @@ union mksh_ccphack {
|
|||||||
const char **ro;
|
const char **ro;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Evil hack since casting uint to sint is implementation-defined
|
||||||
|
*/
|
||||||
|
typedef union {
|
||||||
|
mksh_ari_t i;
|
||||||
|
mksh_uari_t u;
|
||||||
|
} mksh_ari_u;
|
||||||
|
|
||||||
/* for const debugging */
|
/* for const debugging */
|
||||||
#if defined(DEBUG) && defined(__GNUC__) && !defined(__ICC) && \
|
#if defined(DEBUG) && defined(__GNUC__) && !defined(__ICC) && \
|
||||||
!defined(__INTEL_COMPILER) && !defined(__SUNPRO_C)
|
!defined(__INTEL_COMPILER) && !defined(__SUNPRO_C)
|
||||||
@ -2011,7 +2019,7 @@ char *arrayname(const char *);
|
|||||||
mksh_uari_t set_array(const char *, bool, const char **);
|
mksh_uari_t set_array(const char *, bool, const char **);
|
||||||
uint32_t hash(const void *);
|
uint32_t hash(const void *);
|
||||||
mksh_ari_t rndget(void);
|
mksh_ari_t rndget(void);
|
||||||
void rndset(long);
|
void rndset(unsigned long);
|
||||||
|
|
||||||
enum Test_op {
|
enum Test_op {
|
||||||
/* non-operator */
|
/* non-operator */
|
||||||
|
73
var.c
73
var.c
@ -27,7 +27,7 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.168 2013/03/31 18:30:05 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.169 2013/04/01 02:37:53 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Variables
|
* Variables
|
||||||
@ -49,7 +49,7 @@ static void unspecial(const char *);
|
|||||||
static void getspec(struct tbl *);
|
static void getspec(struct tbl *);
|
||||||
static void setspec(struct tbl *);
|
static void setspec(struct tbl *);
|
||||||
static void unsetspec(struct tbl *);
|
static void unsetspec(struct tbl *);
|
||||||
static int getint(struct tbl *, mksh_ari_t *, bool);
|
static int getint(struct tbl *, mksh_ari_u *, bool);
|
||||||
static const char *array_index_calc(const char *, bool *, uint32_t *);
|
static const char *array_index_calc(const char *, bool *, uint32_t *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -471,12 +471,12 @@ setint(struct tbl *vq, mksh_ari_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
|
||||||
{
|
{
|
||||||
int c, base, neg;
|
int c, base;
|
||||||
mksh_uari_t num;
|
mksh_uari_t num;
|
||||||
const char *s;
|
const char *s;
|
||||||
bool have_base = false;
|
bool have_base = false, neg = false;
|
||||||
|
|
||||||
if (vp->flag&SPECIAL)
|
if (vp->flag&SPECIAL)
|
||||||
getspec(vp);
|
getspec(vp);
|
||||||
@ -484,13 +484,12 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
if (!(vp->flag&ISSET) || (!(vp->flag&INTEGER) && vp->val.s == NULL))
|
if (!(vp->flag&ISSET) || (!(vp->flag&INTEGER) && vp->val.s == NULL))
|
||||||
return (-1);
|
return (-1);
|
||||||
if (vp->flag&INTEGER) {
|
if (vp->flag&INTEGER) {
|
||||||
*nump = vp->val.i;
|
nump->i = vp->val.i;
|
||||||
return (vp->type);
|
return (vp->type);
|
||||||
}
|
}
|
||||||
s = vp->val.s + vp->type;
|
s = vp->val.s + vp->type;
|
||||||
base = 10;
|
base = 10;
|
||||||
num = 0;
|
num = 0;
|
||||||
neg = 0;
|
|
||||||
if (arith && s[0] == '0' && (s[1] | 0x20) == 'x') {
|
if (arith && s[0] == '0' && (s[1] | 0x20) == 'x') {
|
||||||
s += 2;
|
s += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
@ -506,7 +505,7 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
#endif
|
#endif
|
||||||
while ((c = *s++)) {
|
while ((c = *s++)) {
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
neg++;
|
neg = true;
|
||||||
continue;
|
continue;
|
||||||
} else if (c == '#') {
|
} else if (c == '#') {
|
||||||
if (have_base || num < 1 || num > 36)
|
if (have_base || num < 1 || num > 36)
|
||||||
@ -525,7 +524,7 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
* not round-tripping correctly XXX)
|
* not round-tripping correctly XXX)
|
||||||
*/
|
*/
|
||||||
wc = 0xEF00 + *(const unsigned char *)s;
|
wc = 0xEF00 + *(const unsigned char *)s;
|
||||||
*nump = (mksh_ari_t)wc;
|
nump->u = (mksh_uari_t)wc;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
num = 0;
|
num = 0;
|
||||||
@ -543,7 +542,9 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
return (-1);
|
return (-1);
|
||||||
num = num * base + c;
|
num = num * base + c;
|
||||||
}
|
}
|
||||||
*nump = neg ? -((mksh_ari_t)num) : (mksh_ari_t)num;
|
if (neg)
|
||||||
|
num = -num;
|
||||||
|
nump->u = num;
|
||||||
return (base);
|
return (base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,11 +556,11 @@ struct tbl *
|
|||||||
setint_v(struct tbl *vq, struct tbl *vp, bool arith)
|
setint_v(struct tbl *vq, struct tbl *vp, bool arith)
|
||||||
{
|
{
|
||||||
int base;
|
int base;
|
||||||
mksh_ari_t num;
|
mksh_ari_u num;
|
||||||
|
|
||||||
if ((base = getint(vp, &num, arith)) == -1)
|
if ((base = getint(vp, &num, arith)) == -1)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
setint_n(vq, num, 0);
|
setint_n(vq, num.i, 0);
|
||||||
if (vq->type == 0)
|
if (vq->type == 0)
|
||||||
/* default base */
|
/* default base */
|
||||||
vq->type = base;
|
vq->type = base;
|
||||||
@ -1097,7 +1098,7 @@ static int user_lineno; /* what user set $LINENO to */
|
|||||||
static void
|
static void
|
||||||
getspec(struct tbl *vp)
|
getspec(struct tbl *vp)
|
||||||
{
|
{
|
||||||
register mksh_ari_t i;
|
mksh_ari_u num;
|
||||||
int st;
|
int st;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
@ -1117,19 +1118,19 @@ getspec(struct tbl *vp)
|
|||||||
}
|
}
|
||||||
switch (st) {
|
switch (st) {
|
||||||
case V_BASHPID:
|
case V_BASHPID:
|
||||||
i = (mksh_ari_t)procpid;
|
num.u = (mksh_uari_t)procpid;
|
||||||
break;
|
break;
|
||||||
case V_COLUMNS:
|
case V_COLUMNS:
|
||||||
i = x_cols;
|
num.i = x_cols;
|
||||||
break;
|
break;
|
||||||
case V_HISTSIZE:
|
case V_HISTSIZE:
|
||||||
i = histsize;
|
num.i = histsize;
|
||||||
break;
|
break;
|
||||||
case V_LINENO:
|
case V_LINENO:
|
||||||
i = current_lineno + user_lineno;
|
num.i = current_lineno + user_lineno;
|
||||||
break;
|
break;
|
||||||
case V_LINES:
|
case V_LINES:
|
||||||
i = x_lins;
|
num.i = x_lins;
|
||||||
break;
|
break;
|
||||||
case V_EPOCHREALTIME: {
|
case V_EPOCHREALTIME: {
|
||||||
/* 10(%u) + 1(.) + 6 + NUL */
|
/* 10(%u) + 1(.) + 6 + NUL */
|
||||||
@ -1144,10 +1145,10 @@ getspec(struct tbl *vp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case V_OPTIND:
|
case V_OPTIND:
|
||||||
i = user_opt.uoptind;
|
num.i = user_opt.uoptind;
|
||||||
break;
|
break;
|
||||||
case V_RANDOM:
|
case V_RANDOM:
|
||||||
i = rndget();
|
num.i = rndget();
|
||||||
break;
|
break;
|
||||||
case V_SECONDS:
|
case V_SECONDS:
|
||||||
/*
|
/*
|
||||||
@ -1157,7 +1158,7 @@ getspec(struct tbl *vp)
|
|||||||
*/
|
*/
|
||||||
if (vp->flag & ISSET) {
|
if (vp->flag & ISSET) {
|
||||||
mksh_TIME(tv);
|
mksh_TIME(tv);
|
||||||
i = tv.tv_sec - seconds;
|
num.i = tv.tv_sec - seconds;
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -1166,14 +1167,14 @@ getspec(struct tbl *vp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vp->flag &= ~SPECIAL;
|
vp->flag &= ~SPECIAL;
|
||||||
setint_n(vp, i, 0);
|
setint_n(vp, num.i, 0);
|
||||||
vp->flag |= SPECIAL;
|
vp->flag |= SPECIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setspec(struct tbl *vp)
|
setspec(struct tbl *vp)
|
||||||
{
|
{
|
||||||
mksh_ari_t i;
|
mksh_ari_u num;
|
||||||
char *s;
|
char *s;
|
||||||
int st;
|
int st;
|
||||||
|
|
||||||
@ -1231,11 +1232,11 @@ setspec(struct tbl *vp)
|
|||||||
case V_SECONDS:
|
case V_SECONDS:
|
||||||
case V_TMOUT:
|
case V_TMOUT:
|
||||||
vp->flag &= ~SPECIAL;
|
vp->flag &= ~SPECIAL;
|
||||||
if (getint(vp, &i, false) == -1) {
|
if (getint(vp, &num, false) == -1) {
|
||||||
s = str_val(vp);
|
s = str_val(vp);
|
||||||
if (st != V_RANDOM)
|
if (st != V_RANDOM)
|
||||||
errorf("%s: %s: %s", vp->name, "bad number", s);
|
errorf("%s: %s: %s", vp->name, "bad number", s);
|
||||||
i = hash(s);
|
num.u = hash(s);
|
||||||
}
|
}
|
||||||
vp->flag |= SPECIAL;
|
vp->flag |= SPECIAL;
|
||||||
break;
|
break;
|
||||||
@ -1248,40 +1249,40 @@ setspec(struct tbl *vp)
|
|||||||
|
|
||||||
switch (st) {
|
switch (st) {
|
||||||
case V_COLUMNS:
|
case V_COLUMNS:
|
||||||
if (i >= MIN_COLS)
|
if (num.i >= MIN_COLS)
|
||||||
x_cols = i;
|
x_cols = num.i;
|
||||||
break;
|
break;
|
||||||
case V_HISTSIZE:
|
case V_HISTSIZE:
|
||||||
sethistsize(i);
|
sethistsize(num.i);
|
||||||
break;
|
break;
|
||||||
case V_LINENO:
|
case V_LINENO:
|
||||||
/* The -1 is because line numbering starts at 1. */
|
/* The -1 is because line numbering starts at 1. */
|
||||||
user_lineno = (unsigned int)i - current_lineno - 1;
|
user_lineno = num.u - current_lineno - 1;
|
||||||
break;
|
break;
|
||||||
case V_LINES:
|
case V_LINES:
|
||||||
if (i >= MIN_LINS)
|
if (num.i >= MIN_LINS)
|
||||||
x_lins = i;
|
x_lins = num.i;
|
||||||
break;
|
break;
|
||||||
case V_OPTIND:
|
case V_OPTIND:
|
||||||
getopts_reset((int)i);
|
getopts_reset((int)num.i);
|
||||||
break;
|
break;
|
||||||
case V_RANDOM:
|
case V_RANDOM:
|
||||||
/*
|
/*
|
||||||
* mksh R39d+ no longer has the traditional repeatability
|
* mksh R39d+ no longer has the traditional repeatability
|
||||||
* of $RANDOM sequences, but always retains state
|
* of $RANDOM sequences, but always retains state
|
||||||
*/
|
*/
|
||||||
rndset((long)i);
|
rndset((unsigned long)num.u);
|
||||||
break;
|
break;
|
||||||
case V_SECONDS:
|
case V_SECONDS:
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
mksh_TIME(tv);
|
mksh_TIME(tv);
|
||||||
seconds = tv.tv_sec - i;
|
seconds = tv.tv_sec - num.i;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case V_TMOUT:
|
case V_TMOUT:
|
||||||
ksh_tmout = i >= 0 ? i : 0;
|
ksh_tmout = num.i >= 0 ? num.i : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1537,7 +1538,7 @@ rndget(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rndset(long v)
|
rndset(unsigned long v)
|
||||||
{
|
{
|
||||||
register uint32_t h;
|
register uint32_t h;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user