• Build.sh: fix NSIG detection for gcc-snapshot

• all: bump version to R50-current; add more comments; whitespace
• all: remove all mkssert(); we’ll do full re-runs of scan-build and,
  hopefully, Coverity Scan/Prevent
• check.t: fix a testcase (sed could exit false, but we don’t care)
• eval.c: fix tilde_ok data type (only unsigned may shl constantly)
• exec.c: fix shebang buf array accesses to always go via uint8_t *
This commit is contained in:
tg 2014-11-25 21:13:31 +00:00
parent 371ee4af07
commit 2f52b993a1
13 changed files with 57 additions and 61 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.670 2014/11/25 20:00:36 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.671 2014/11/25 21:13:18 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014 # 2011, 2012, 2013, 2014
@ -1784,7 +1784,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.670 2014/11/25 20:00:36 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.671 2014/11/25 21:13:18 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (isatty(0)); } int main(void) { printf("Hello, World!\n"); return (isatty(0)); }
EOF EOF
case $cm in case $cm in
@ -2263,6 +2263,11 @@ mksh_cfg= NSIG
;' >conftest.c ;' >conftest.c
# GNU sed 2.03 segfaults when optimising this to sed -n # GNU sed 2.03 segfaults when optimising this to sed -n
NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
grep -v '^#' | \
sed '/mksh_cfg.*= *$/{
N
s/\n/ /
}' | \
grep '^ *mksh_cfg *=' | \ grep '^ *mksh_cfg *=' | \
sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'` sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'`
case $NSIG in case $NSIG in
@ -2294,6 +2299,11 @@ mksh_cfg= NSIG
echo ';' >>conftest.c echo ';' >>conftest.c
# GNU sed 2.03 croaks on optimising this, too # GNU sed 2.03 croaks on optimising this, too
vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \
grep -v '^#' | \
sed '/mksh_cfg.*= *$/{
N
s/\n/ /
}' | \
grep '^ *mksh_cfg *=' | \ grep '^ *mksh_cfg *=' | \
sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/ sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/
done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do done | sed -n '/^:[^ ]/s/^://p' | while read nr name; do
@ -2315,7 +2325,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c
addsrcs USE_PRINTF_BUILTIN printf.c addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
add_cppflags -DMKSH_BUILD_R=504 add_cppflags -DMKSH_BUILD_R=509
$e $bi$me: Finished configuration testing, now producing output.$ao $e $bi$me: Finished configuration testing, now producing output.$ao

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.138 2014/10/07 15:22:13 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.139 2014/11/25 21:13:19 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014 # 2011, 2012, 2013, 2014
@ -55,7 +55,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \ -DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \ -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ -DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=504 -DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=509
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U} CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
CPPFLAGS+= -I. CPPFLAGS+= -I.
COPTS+= -std=c89 -Wall COPTS+= -std=c89 -Wall

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.670 2014/11/19 18:44:09 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.671 2014/11/25 21:13:19 tg Exp $
# OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44 # OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -27,7 +27,7 @@
# http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R50 2014/11/19 @(#)MIRBSD KSH R50 2014/11/25
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -36,7 +36,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R50 2014/11/19 @(#)LEGACY KSH R50 2014/11/25
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -7141,6 +7141,7 @@ description:
XXX if the OS can already execute them, we lose XXX if the OS can already execute them, we lose
note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
need-pass: no need-pass: no
category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
env-setup: !FOO=BAR! env-setup: !FOO=BAR!
@ -11060,6 +11061,7 @@ stdin:
(mypid=$$; try mypid) (mypid=$$; try mypid)
echo =15 echo =15
) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//' ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
exit ${PIPESTATUS[0]}
expected-stdout: expected-stdout:
y y
=1 =1

5
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.279 2014/11/19 21:52:16 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.280 2014/11/25 21:13:22 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -593,8 +593,6 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp,
char **words = NULL; char **words = NULL;
bool is_command; bool is_command;
mkssert(buf != NULL);
len = x_locate_word(buf, buflen, pos, startp, &is_command); len = x_locate_word(buf, buflen, pos, startp, &is_command);
if (!((*flagsp) & XCF_COMMAND)) if (!((*flagsp) & XCF_COMMAND))
is_command = false; is_command = false;
@ -2240,7 +2238,6 @@ x_push(int nchars)
{ {
char *cp; char *cp;
mkssert(xcp != NULL);
strndupx(cp, xcp, nchars, AEDIT); strndupx(cp, xcp, nchars, AEDIT);
if (killstack[killsp]) if (killstack[killsp])
afree(killstack[killsp], AEDIT); afree(killstack[killsp], AEDIT);

5
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.159 2014/11/19 21:49:12 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.160 2014/11/25 21:13:23 tg Exp $");
/* /*
* string expansion * string expansion
@ -237,7 +237,7 @@ expand(
/* record number of trailing newlines in COMSUB */ /* record number of trailing newlines in COMSUB */
int newlines = 0; int newlines = 0;
bool saw_eq, make_magic; bool saw_eq, make_magic;
int tilde_ok; unsigned int tilde_ok;
size_t len; size_t len;
char *cp; char *cp;
@ -516,7 +516,6 @@ expand(
/* check for special cases */ /* check for special cases */
d = str_val(st->var); d = str_val(st->var);
mkssert(d != NULL);
switch (*pat) { switch (*pat) {
case '#': case '#':
/* anchor at begin */ /* anchor at begin */

13
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.137 2014/10/19 21:53:07 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.138 2014/11/25 21:13:24 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh" #define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -924,11 +924,12 @@ scriptexec(struct op *tp, const char **ap)
*tp->args-- = (char *)cp; *tp->args-- = (char *)cp;
} }
noshebang: noshebang:
if (buf[0] == 0x7F && buf[1] == 'E' && buf[2] == 'L' && cp = (unsigned char *)buf;
buf[3] == 'F') if (cp[0] == 0x7F && cp[1] == 'E' && cp[2] == 'L' &&
cp[3] == 'F')
errorf("%s: not executable: %d-bit ELF file", tp->str, errorf("%s: not executable: %d-bit ELF file", tp->str,
32 * ((uint8_t)buf[4])); 32 * cp[4]);
fd = buf[0] << 8 | buf[1]; fd = cp[0] << 8 | cp[1];
if ((fd == /* OMAGIC */ 0407) || if ((fd == /* OMAGIC */ 0407) ||
(fd == /* NMAGIC */ 0410) || (fd == /* NMAGIC */ 0410) ||
(fd == /* ZMAGIC */ 0413) || (fd == /* ZMAGIC */ 0413) ||
@ -1006,8 +1007,6 @@ define(const char *name, struct op *t)
while (/* CONSTCOND */ 1) { while (/* CONSTCOND */ 1) {
tp = findfunc(name, nhash, true); tp = findfunc(name, nhash, true);
/* because findfunc:create=true */
mkssert(tp != NULL);
if (tp->flag & ISSET) if (tp->flag & ISSET)
was_set = true; was_set = true;

View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.260 2014/11/25 20:00:37 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.261 2014/11/25 21:13:25 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -2797,8 +2797,6 @@ c_test(const char **wp)
for (argc = 0; wp[argc]; argc++) for (argc = 0; wp[argc]; argc++)
; ;
mkssert(argc > 0);
mkssert(wp[0] != NULL);
if (strcmp(wp[0], "[") == 0) { if (strcmp(wp[0], "[") == 0) {
if (strcmp(wp[--argc], "]") != 0) { if (strcmp(wp[--argc], "]") != 0) {

View File

@ -27,7 +27,7 @@
#include <sys/file.h> #include <sys/file.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.135 2014/11/25 20:00:38 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.136 2014/11/25 21:13:26 tg Exp $");
Trap sigtraps[NSIG + 1]; Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign; static struct sigaction Sigact_ign;
@ -634,7 +634,6 @@ histsave(int *lnp, const char *cmd, bool dowrite MKSH_A_UNUSED, bool ignoredups)
char **hp; char **hp;
char *c, *cp; char *c, *cp;
mkssert(cmd != NULL);
strdupx(c, cmd, APERM); strdupx(c, cmd, APERM);
if ((cp = strchr(c, '\n')) != NULL) if ((cp = strchr(c, '\n')) != NULL)
*cp = '\0'; *cp = '\0';

4
jobs.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.105 2014/10/03 12:32:48 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.106 2014/11/25 21:13:27 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
#define mksh_killpg killpg #define mksh_killpg killpg
@ -1789,7 +1789,6 @@ remove_job(Job *j, const char *where)
Proc *p, *tmp; Proc *p, *tmp;
Job **prev, *curr; Job **prev, *curr;
mkssert(j != NULL);
prev = &job_list; prev = &job_list;
curr = job_list; curr = job_list;
while (curr && curr != j) { while (curr && curr != j) {
@ -1832,7 +1831,6 @@ put_job(Job *j, int where)
{ {
Job **prev, *curr; Job **prev, *curr;
mkssert(j != NULL);
/* Remove job from list (if there) */ /* Remove job from list (if there) */
prev = &job_list; prev = &job_list;
curr = job_list; curr = job_list;

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.285 2014/10/12 21:58:52 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.286 2014/11/25 21:13:28 tg Exp $");
extern char **environ; extern char **environ;
@ -1014,8 +1014,6 @@ cleanup_parents_env(void)
struct env *ep; struct env *ep;
int fd; int fd;
mkssert(e != NULL);
/* /*
* Don't clean up temporary files - parent will probably need them. * Don't clean up temporary files - parent will probably need them.
* Also, can't easily reclaim memory since variables, etc. could be * Also, can't easily reclaim memory since variables, etc. could be

3
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.220 2014/11/25 20:00:39 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.221 2014/11/25 21:13:29 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -485,7 +485,6 @@ parse_args(const char **argv,
if (arrayset) { if (arrayset) {
const char *ccp = NULL; const char *ccp = NULL;
mkssert(array != NULL);
if (*array) if (*array)
ccp = skip_varname(array, false); ccp = skip_varname(array, false);
if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) { if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {

6
sh.h
View File

@ -169,9 +169,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.704 2014/11/19 21:49:12 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.705 2014/11/25 21:13:29 tg Exp $");
#endif #endif
#define MKSH_VERSION "R50 2014/11/19" #define MKSH_VERSION "R50 2014/11/25"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES
@ -533,7 +533,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0) #define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif #endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 504) #if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 509)
#error Must run Build.sh to compile this. #error Must run Build.sh to compile this.
extern void thiswillneverbedefinedIhope(void); extern void thiswillneverbedefinedIhope(void);
int int

5
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.183 2014/10/04 11:47:19 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.184 2014/11/25 21:13:31 tg Exp $");
/*- /*-
* Variables * Variables
@ -308,7 +308,6 @@ local(const char *n, bool copy)
* dereference namerefs; must come first * dereference namerefs; must come first
*/ */
n = array_index_calc(n, &array, &val); n = array_index_calc(n, &array, &val);
mkssert(n != NULL);
h = hash(n); h = hash(n);
if (!ksh_isalphx(*n)) { if (!ksh_isalphx(*n)) {
vp = &vtemp; vp = &vtemp;
@ -679,8 +678,6 @@ exportprep(struct tbl *vp, const char *val)
char *op = (vp->flag&ALLOC) ? vp->val.s : NULL; char *op = (vp->flag&ALLOC) ? vp->val.s : NULL;
size_t namelen, vallen; size_t namelen, vallen;
mkssert(val != NULL);
namelen = strlen(vp->name); namelen = strlen(vp->name);
vallen = strlen(val) + 1; vallen = strlen(val) + 1;