couple of minor/cosmetic fixes from RT’s compile farm:

• promote SCO OpenServer and UnixWare to !oswarn
• omit trying -O2/-O on OpenServer 5 and USL C
• cast mksh_ari_t to int, mksh_uari_t to unsigned int for printf
• skip ulimit-1 on syllable (which is still too broken)
• write ((mksh_ari_t)-2147483648) ipv UB ((mksh_ari_t)1 << 31)
  and add a comment that that is actually meant
• rewrite functions returning !void ending in NOTREACHED
  so they’ve got a jump target returning an error at the
  end, to aid older compilers and just to be safe
• cast struct stat.st_size to off_t or size_t explicitly when needed
• shorten struct env by two bytes and an alignment, at least

also, optimise control flow and fix more paren matching cases
This commit is contained in:
tg 2012-03-29 19:23:01 +00:00
parent 45fa321c23
commit cf75e7b6ce
8 changed files with 43 additions and 33 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.524 2012/03/28 11:15:04 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.525 2012/03/29 19:22:54 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012
@ -571,7 +571,6 @@ QNX)
: ${HAVE_SETLOCALE_CTYPE=0}
;;
SCO_SV)
oswarn='; it may actually work'
case $TARGET_OSREV in
3.2*)
# SCO OpenServer 5
@ -606,7 +605,6 @@ ULTRIX)
;;
UnixWare|UNIX_SV)
# SCO UnixWare
oswarn='; it may work well'
;;
UWIN*)
ccpc='-Yc,'
@ -860,6 +858,7 @@ uslc)
SCO_SV:3.2*)
# SCO OpenServer 5
CFLAGS="$CFLAGS -g"
: ${HAVE_CAN_OTWO=0} ${HAVE_CAN_OPTIMISE=0}
;;
esac
vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
@ -1339,7 +1338,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.524 2012/03/28 11:15:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.525 2012/03/29 19:22:54 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -1661,7 +1660,8 @@ if ac_testnnd silent_idivwrapv '' '(run-time) whether signed integer division ov
printf("si");
return (0);
}
printf("no %d %d %d %d %s", o1, o2, r1, r2, av[0]);
printf("no %d %d %d %d %s", (int)o1, (int)o2, (int)r1,
(int)r2, av[0]);
return (1);
}
#ifdef SIGFPE

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.524 2012/03/27 22:36:49 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.525 2012/03/29 19:22:55 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/03/27
@(#)MIRBSD KSH R40 2012/03/29
description:
Check version of shell.
stdin:
@ -7875,6 +7875,7 @@ expected-stdout:
name: ulimit-1
description:
Check if we can use a specific syntax idiom for ulimit
category: !os:syllable
stdin:
if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
#echo expected to fail on this OS

5
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.114 2012/03/27 22:58:38 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.115 2012/03/29 19:22:57 tg Exp $");
/*
* string expansion
@ -393,7 +393,8 @@ expand(const char *cp, /* input word */
NZATUpdateString(h,
str_val(st->var));
NZATFinish(h);
x.str = shf_smprintf("%08X", h);
x.str = shf_smprintf("%08X",
(unsigned int)h);
break;
}
case '0': {

12
expr.c
View File

@ -1,7 +1,8 @@
/* $OpenBSD: expr.c,v 1.21 2009/06/01 19:00:57 deraadt Exp $ */
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012
* Thorsten Glaser <tg@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@ -22,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.53 2011/12/31 02:04:18 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.54 2012/03/29 19:22:58 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -368,10 +369,11 @@ evalexpr(Expr_state *es, int prec)
case O_DIVASN:
#if !HAVE_SILENT_IDIVWRAPV
if (!es->natural && vr->val.i == -1 &&
vl->val.i == ((mksh_ari_t)1 << 31)) {
vl->val.i == ((mksh_ari_t)-2147483648)) {
/* -2147483648 / -1 = 2147483648 */
/* this ^ is really (1 << 31) though */
/* 80000000 / FFFFFFFF = 80000000 */
res = ((mksh_ari_t)1 << 31);
res = ((mksh_ari_t)-2147483648);
} else
#endif
res = bivui(vl, /, vr);
@ -380,7 +382,7 @@ evalexpr(Expr_state *es, int prec)
case O_MODASN:
#if !HAVE_SILENT_IDIVWRAPV
if (!es->natural && vr->val.i == -1 &&
vl->val.i == ((mksh_ari_t)1 << 31)) {
vl->val.i == ((mksh_ari_t)-2147483648)) {
/* -2147483648 % -1 = 0 */
res = 0;
} else

24
funcs.c
View File

@ -5,7 +5,7 @@
/*-
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
* 2010, 2011
* 2010, 2011, 2012
* Thorsten Glaser <tg@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.210 2012/03/26 21:10:42 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.211 2012/03/29 19:22:58 tg Exp $");
#if HAVE_KILLPG
/*
@ -2253,7 +2253,7 @@ c_exitreturn(const char **wp)
const char *arg;
if (ksh_getopt(wp, &builtin_opt, null) == '?')
return (1);
goto c_exitreturn_err;
arg = wp[builtin_opt.optind];
if (arg) {
@ -2288,6 +2288,9 @@ c_exitreturn(const char **wp)
quitenv(NULL);
unwind(how);
/* NOTREACHED */
c_exitreturn_err:
return (1);
}
int
@ -2298,19 +2301,19 @@ c_brkcont(const char **wp)
const char *arg;
if (ksh_getopt(wp, &builtin_opt, null) == '?')
return (1);
goto c_brkcont_err;
arg = wp[builtin_opt.optind];
if (!arg)
n = 1;
else if (!bi_getn(arg, &n))
return (1);
quit = n;
if (quit <= 0) {
goto c_brkcont_err;
if (n <= 0) {
/* AT&T ksh does this for non-interactive shells only - weird */
bi_errorf("%s: %s", arg, "bad value");
return (1);
goto c_brkcont_err;
}
quit = n;
/* Stop at E_NONE, E_PARSE, E_FUNC, or E_INCL */
for (ep = e; ep && !STOP_BRKCONT(ep->type); ep = ep->oenv)
@ -2344,6 +2347,9 @@ c_brkcont(const char **wp)
unwind(*wp[0] == 'b' ? LBREAK : LCONTIN);
/* NOTREACHED */
c_brkcont_err:
return (1);
}
int
@ -2974,7 +2980,7 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
/* -s */
case TO_FILGZ:
return (stat(opnd1, &b1) == 0 && b1.st_size > 0L);
return (stat(opnd1, &b1) == 0 && (off_t)b1.st_size > (off_t)0);
/* -t */
case TO_FILTT:

View File

@ -27,7 +27,7 @@
#include <sys/file.h>
#endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.119 2012/03/28 23:07:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.120 2012/03/29 19:22:59 tg Exp $");
Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign;
@ -342,7 +342,7 @@ c_fc(const char **wp)
"file", (unsigned long)statb.st_size);
goto errout;
} else
n = statb.st_size + 1;
n = (size_t)statb.st_size + 1;
Xinit(xs, xp, n, hist_source->areap);
while ((n = shf_read(xp, Xnleft(xs, xp), shf)) > 0) {
xp += n;

4
lex.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.158 2011/11/26 17:56:30 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.159 2012/03/29 19:23:00 tg Exp $");
/*
* states while lexing word
@ -1633,7 +1633,7 @@ get_brace_var(XString *wsp, char *wp)
c2 = getsc();
ungetsc(c2);
if (c2 != '}') {
if (c2 != /*{*/ '}') {
ungetsc(c);
goto out;
}

12
sh.h
View File

@ -152,9 +152,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.537 2012/03/28 23:09:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.538 2012/03/29 19:23:01 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/03/27"
#define MKSH_VERSION "R40 2012/03/29"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -590,8 +590,8 @@ extern struct env {
short *savefd; /* original redirected fds */
struct temp *temps; /* temp files */
sigjmp_buf jbuf; /* long jump back to env creator */
short type; /* environment type - see below */
short flags; /* EF_* */
uint8_t type; /* environment type - see below */
uint8_t flags; /* EF_* */
} *e;
/* struct env.type values */
@ -610,8 +610,8 @@ extern struct env {
#define EF_FAKE_SIGDIE BIT(2) /* hack to get info from unwind to quitenv */
/* Do breaks/continues stop at env type e? */
#define STOP_BRKCONT(t) ((t) == E_NONE || (t) == E_PARSE \
|| (t) == E_FUNC || (t) == E_INCL)
#define STOP_BRKCONT(t) ((t) == E_NONE || (t) == E_PARSE || \
(t) == E_FUNC || (t) == E_INCL)
/* Do returns stop at env type e? */
#define STOP_RETURN(t) ((t) == E_FUNC || (t) == E_INCL)