even more hacks to pass “-O666 -fstrict-overflow -Wstrict-overflow=9 -flto=jobserver” with “gcc version 4.8.0 20120930 (experimental) [trunk revision 191865] (Debian 20120930-1)” ☹ plus make the rtchecks mandatory

This commit is contained in:
tg 2012-10-03 17:24:23 +00:00
parent c39bfe09ee
commit d8662eb228
9 changed files with 115 additions and 69 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.584 2012/09/28 18:57:49 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.585 2012/10/03 17:24:13 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012
@ -1492,7 +1492,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.584 2012/09/28 18:57:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.585 2012/10/03 17:24:13 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -1784,9 +1784,11 @@ cta(long_size_no_matter_of_signedness, sizeof(long) == sizeof(unsigned long));
cta(ari_is_4_char, sizeof(mksh_ari_t) == 4);
/* but the next two are; we REQUIRE signed integer wraparound */
cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
#ifndef MKSH_GCC565048
cta(ari_sign_32_bit_and_wrap,
(mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1) >
(mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 2));
#endif
/* the next assertion is probably not really needed */
cta(uari_is_4_char, sizeof(mksh_uari_t) == 4);
/* but the next three are; we REQUIRE unsigned integer wraparound */
@ -1807,7 +1809,17 @@ cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)(void)));
/* our formatting routines assume this */
cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long));
};
int main(void) { return (sizeof(struct ctasserts)); }
#ifndef MKSH_LEGACY_MODE
#ifndef MKSH_GCC565048
#define NUM 22
#else
#define NUM 21
#endif
#else
#define NUM 15
#endif
char ctasserts_dblcheck[sizeof(struct ctasserts) == NUM ? 1 : -1];
int main(void) { return (sizeof(ctasserts_dblcheck)); }
EOF
CFLAGS=$save_CFLAGS
eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1

42
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.558 2012/09/07 21:02:40 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.559 2012/10/03 17:24:14 tg 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: 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
expected-stdout:
@(#)MIRBSD KSH R40 2012/09/07
@(#)MIRBSD KSH R40 2012/10/03
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R40 2012/09/07
@(#)LEGACY KSH R40 2012/10/03
description:
Check version of legacy shell.
stdin:
@ -354,6 +354,42 @@ expected-stdout:
6
6,5,3
---
name: arith-mandatory
description:
If MKSH_GCC565048 is set when compiling, passing of
this test is *mandatory* for a valid mksh executable!
category: shell:legacy-no
stdin:
typeset -i sari=0
typeset -Ui uari=0
typeset -i x=0
print -r -- $((x++)):$sari=$uari.
let --sari --uari
print -r -- $((x++)):$sari=$uari.
sari=2147483647 uari=2147483647
print -r -- $((x++)):$sari=$uari.
let ++sari ++uari
print -r -- $((x++)):$sari=$uari.
let --sari --uari
let 'sari *= 2' 'uari *= 2'
let ++sari ++uari
print -r -- $((x++)):$sari=$uari.
let ++sari ++uari
print -r -- $((x++)):$sari=$uari.
sari=-2147483648 uari=-2147483648
print -r -- $((x++)):$sari=$uari.
let --sari --uari
print -r -- $((x++)):$sari=$uari.
expected-stdout:
0:0=0.
1:-1=4294967295.
2:2147483647=2147483647.
3:-2147483648=2147483648.
4:-1=4294967295.
5:0=0.
6:-2147483648=2147483648.
7:2147483647=2147483647.
---
name: arith-unsigned-1
description:
Check if unsigned arithmetics work

41
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.253 2012/10/03 15:50:29 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.254 2012/10/03 17:24:17 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -1378,10 +1378,10 @@ static int
x_del_char(int c MKSH_A_UNUSED)
{
char *cp, *cp2;
ssize_t i = 0;
size_t i = 0;
cp = xcp;
while (i < x_arg) {
while (i < (size_t)x_arg) {
utf_ptradjx(cp, cp2);
if (cp2 > xep)
break;
@ -1904,7 +1904,7 @@ x_search_hist(int c)
} else if (f == XFUNC_insert) {
/* add char to pattern */
/* overflow check... */
if (p >= &pat[sizeof(pat) - 1]) {
if ((size_t)(p - pat) >= sizeof(pat) - 1) {
x_e_putc2(7);
continue;
}
@ -2498,7 +2498,7 @@ x_bind(const char *a1, const char *a2,
char msg[256];
const char *c = a1;
m1 = msg;
while (*c && m1 < (msg + sizeof(msg) - 3))
while (*c && (size_t)(m1 - msg) < sizeof(msg) - 3)
x_mapout2(*c++, &m1);
bi_errorf("%s: %s", "too long key sequence", msg);
return (1);
@ -2584,9 +2584,14 @@ x_init_emacs(void)
static void
bind_if_not_bound(int p, int k, int func)
{
/* Has user already bound this key? If so, don't override it */
if (x_bound[((p) * X_TABSZ + (k)) / 8] &
(1 << (((p) * X_TABSZ + (k)) % 8)))
int t;
/*
* Has user already bound this key?
* If so, do not override it.
*/
t = p * X_TABSZ + k;
if (x_bound[t >> 3] & (1 << (t & 7)))
return;
x_tab[p][k] = func;
@ -3544,7 +3549,7 @@ x_vi(char *buf, size_t len)
cur_col -= prompt_trunc;
pprompt(prompt, 0);
if (cur_col > x_cols - 3 - MIN_EDIT_SPACE) {
if ((mksh_uari_t)cur_col > (mksh_uari_t)x_cols - 3 - MIN_EDIT_SPACE) {
prompt_redraw = false;
cur_col = 0;
x_putc('\n');
@ -3812,7 +3817,8 @@ vi_hook(int ch)
else {
locpat[srchlen++] = ch;
if (ch < ' ' || ch == 0x7f) {
if (es->linelen + 2 > es->cbufsize)
if ((size_t)es->linelen + 2 >
(size_t)es->cbufsize)
vi_error();
es->cbuf[es->linelen++] = '^';
es->cbuf[es->linelen++] = ch ^ '@';
@ -4403,7 +4409,7 @@ vi_cmd(int argcnt, const char *cmd)
break;
case '_':
{
int inspace;
bool inspace;
char *p, *sp;
if (histnum(-1) < 0)
@ -4424,12 +4430,12 @@ vi_cmd(int argcnt, const char *cmd)
sp = p;
} else {
sp = p;
inspace = 0;
inspace = false;
while (*p) {
if (issp(*p))
inspace = 1;
inspace = true;
else if (inspace) {
inspace = 0;
inspace = false;
sp = p;
}
p++;
@ -4444,11 +4450,8 @@ vi_cmd(int argcnt, const char *cmd)
argcnt++;
p++;
}
if (putbuf(" ", 1, 0) != 0)
argcnt = -1;
else if (putbuf(sp, argcnt, 0) != 0)
argcnt = -1;
if (argcnt < 0) {
if (putbuf(" ", 1, 0) != 0 ||
putbuf(sp, argcnt, 0) != 0) {
if (es->cursor != 0)
es->cursor--;
return (-1);

9
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.100 2012/10/03 15:13:30 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.101 2012/10/03 17:24:18 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -1653,9 +1653,10 @@ dbteste_isa(Test_env *te, Test_meta meta)
char buf[8];
char *q = buf;
for (p = *te->pos.wp;
*p == CHAR && q < &buf[sizeof(buf) - 1]; p += 2)
*q++ = p[1];
p = *te->pos.wp;
while (*p++ == CHAR &&
(size_t)(q - buf) < sizeof(buf) - 1)
*q++ = *p++;
*q = '\0';
ret = test_isop(meta, buf);
}

26
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.59 2012/09/01 23:46:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.60 2012/10/03 17:24:19 tg Exp $");
#if !HAVE_SILENT_IDIVWRAPV
#if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
@ -153,15 +153,9 @@ struct expr_state {
};
#define bivui(x, op, y) (es->natural ? \
(mksh_ari_t)((x)->val.u op (y)->val.u) : \
(mksh_ari_t)((x)->val.i op (y)->val.i) \
(mksh_uari_t)((x)->val.u op (y)->val.u) : \
(mksh_uari_t)((x)->val.i op (y)->val.i) \
)
#define stvui(x, n) do { \
if (es->natural) \
(x)->val.u = (n); \
else \
(x)->val.i = (n); \
} while (/* CONSTCOND */ 0)
enum error_type {
ET_UNEXPECTED, ET_BADLIT, ET_RECURSIVE,
@ -313,7 +307,7 @@ evalexpr(Expr_state *es, int prec)
{
struct tbl *vl, *vr = NULL, *vasn;
enum token op;
mksh_ari_t res = 0;
mksh_uari_t res = 0;
if (prec == P_PRIMARY) {
op = es->tok;
@ -392,7 +386,7 @@ evalexpr(Expr_state *es, int prec)
vr->val.u == IDIVWRAPV_VR) {
/* -2147483648 / -1 = 2147483648 */
/* this ^ is really (1 << 31) though */
res = (mksh_ari_t)IDIVWRAPV_VL;
res = IDIVWRAPV_VL;
} else
#endif
res = bivui(vl, /, vr);
@ -493,23 +487,23 @@ evalexpr(Expr_state *es, int prec)
}
break;
case O_ASN:
res = vr->val.i;
res = vr->val.u;
break;
case O_COMMA:
res = vr->val.i;
res = vr->val.u;
break;
}
if (IS_ASSIGNOP(op)) {
stvui(vr, res);
vr->val.u = res;
if (!es->noassign) {
if (vasn->flag & INTEGER)
setint_v(vasn, vr, es->arith);
else
setint(vasn, res);
setint(vasn, (mksh_ari_t)res);
}
vl = vr;
} else if (op != O_TERN)
stvui(vl, res);
vl->val.u = res;
}
return (vl);
}

15
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.225 2012/10/03 16:16:12 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.226 2012/10/03 17:24:19 tg Exp $");
#if HAVE_KILLPG
/*
@ -1899,7 +1899,7 @@ c_read(const char **wp)
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
FD_SET((unsigned int)fd, &fdset);
mksh_TIME(tv);
timersub(&tvlim, &tv, &tv);
if (tv.tv_sec < 0) {
@ -2315,7 +2315,8 @@ c_exitreturn(const char **wp)
int
c_brkcont(const char **wp)
{
int n, quit;
unsigned int quit;
int n;
struct env *ep, *last_ep = NULL;
const char *arg;
@ -2332,7 +2333,7 @@ c_brkcont(const char **wp)
bi_errorf("%s: %s", arg, "bad value");
goto c_brkcont_err;
}
quit = n;
quit = (unsigned int)n;
/* Stop at E_NONE, E_PARSE, E_FUNC, or E_INCL */
for (ep = e; ep && !STOP_BRKCONT(ep->type); ep = ep->oenv)
@ -2349,7 +2350,7 @@ c_brkcont(const char **wp)
* can. We print a message 'cause it helps in debugging
* scripts, but don't generate an error (ie, keep going).
*/
if (n == quit) {
if ((unsigned int)n == quit) {
warningf(true, "%s: %s %s", wp[0], "can't", wp[0]);
return (0);
}
@ -2360,8 +2361,8 @@ c_brkcont(const char **wp)
*/
if (last_ep)
last_ep->flags &= ~EF_BRKCONT_PASS;
warningf(true, "%s: can only %s %d level(s)",
wp[0], wp[0], n - quit);
warningf(true, "%s: can only %s %u level(s)",
wp[0], wp[0], (unsigned int)n - quit);
}
unwind(*wp[0] == 'b' ? LBREAK : LCONTIN);

10
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.167 2012/08/17 18:34:21 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.168 2012/10/03 17:24:20 tg Exp $");
/*
* states while lexing word
@ -1034,17 +1034,17 @@ yylex(int cf)
sp = yylval.cp;
dp = ident;
if ((cf & HEREDELIM) && (sp[1] == '<'))
while (dp < ident+IDENT) {
while ((dp - ident) < IDENT) {
if ((c = *sp++) == CHAR)
*dp++ = *sp++;
else if ((c != OQUOTE) && (c != CQUOTE))
break;
}
else
while (dp < ident+IDENT && (c = *sp++) == CHAR)
while ((dp - ident) < IDENT && (c = *sp++) == CHAR)
*dp++ = *sp++;
/* Make sure the ident array stays '\0' padded */
memset(dp, 0, (ident+IDENT) - dp + 1);
memset(dp, 0, (ident + IDENT) - dp + 1);
if (c != EOS)
/* word is not unquoted */
*ident = '\0';
@ -1677,7 +1677,7 @@ arraysub(char **strp)
XString ws;
char *wp, c;
/* we are just past the initial [ */
int depth = 1;
unsigned int depth = 1;
Xinit(ws, wp, 32, ATEMP);

19
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.198 2012/10/03 15:13:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.199 2012/10/03 17:24:21 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -469,8 +469,10 @@ parse_args(const char **argv,
int
getn(const char *s, int *ai)
{
int i, c, rv = 0;
int c;
unsigned int i, j, k;
bool neg = false;
int rv = 0;
do {
c = *s++;
@ -480,22 +482,19 @@ getn(const char *s, int *ai)
c = *s++;
} else if (c == '+')
c = *s++;
*ai = i = 0;
k = neg ? 2147483648U : 2147483647U;
j = i = 0;
do {
if (!ksh_isdigit(c))
goto getn_out;
i *= 10;
if (i < *ai)
/* overflow */
if ((j = i * 10 + c - '0') > k)
goto getn_out;
i += c - '0';
*ai = i;
i = j;
} while ((c = *s++));
rv = 1;
getn_out:
if (neg)
*ai = -*ai;
*ai = i == 2147483648U ? -2147483648 : neg ? -(int)i : (int)i;
return (rv);
}

4
sh.h
View File

@ -157,9 +157,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.591 2012/10/03 16:16:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.592 2012/10/03 17:24:23 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/09/07"
#define MKSH_VERSION "R40 2012/10/03"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES