From 2f52b993a133b7fbd7dff1b13a1fab8e6008d3ea Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 25 Nov 2014 21:13:31 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20Build.sh:=20fix=20NSIG=20detection?= =?UTF-8?q?=20for=20gcc-snapshot=20=E2=80=A2=20all:=20bump=20version=20to?= =?UTF-8?q?=20R50-current;=20add=20more=20comments;=20whitespace=20?= =?UTF-8?q?=E2=80=A2=20all:=20remove=20all=20mkssert();=20we=E2=80=99ll=20?= =?UTF-8?q?do=20full=20re-runs=20of=20scan-build=20and,=20=20=20hopefully,?= =?UTF-8?q?=20Coverity=20Scan/Prevent=20=E2=80=A2=20check.t:=20fix=20a=20t?= =?UTF-8?q?estcase=20(sed=20could=20exit=20false,=20but=20we=20don?= =?UTF-8?q?=E2=80=99t=20care)=20=E2=80=A2=20eval.c:=20fix=20tilde=5Fok=20d?= =?UTF-8?q?ata=20type=20(only=20unsigned=20may=20shl=20constantly)=20?= =?UTF-8?q?=E2=80=A2=20exec.c:=20fix=20shebang=20buf=20array=20accesses=20?= =?UTF-8?q?to=20always=20go=20via=20uint8=5Ft=20*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Build.sh | 16 +++++++++++++--- Makefile | 4 ++-- check.t | 8 +++++--- edit.c | 5 +---- eval.c | 5 ++--- exec.c | 13 ++++++------- funcs.c | 4 +--- histrap.c | 3 +-- jobs.c | 42 ++++++++++++++++++++---------------------- main.c | 4 +--- misc.c | 3 +-- sh.h | 6 +++--- var.c | 5 +---- 13 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Build.sh b/Build.sh index c264f1f..63c2ae5 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/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, # 2011, 2012, 2013, 2014 @@ -1784,7 +1784,7 @@ else #define EXTERN #define MKSH_INCLUDES_ONLY #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)); } EOF case $cm in @@ -2263,6 +2263,11 @@ mksh_cfg= NSIG ;' >conftest.c # GNU sed 2.03 segfaults when optimising this to sed -n NSIG=`vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ + grep -v '^#' | \ + sed '/mksh_cfg.*= *$/{ + N + s/\n/ / + }' | \ grep '^ *mksh_cfg *=' | \ sed 's/^ *mksh_cfg *=[ ]*\([()0-9x+-][()0-9x+ -]*\).*$/\1/'` case $NSIG in @@ -2294,6 +2299,11 @@ mksh_cfg= NSIG echo ';' >>conftest.c # GNU sed 2.03 croaks on optimising this, too vq "$CPP $CFLAGS $CPPFLAGS $NOWARN conftest.c" | \ + grep -v '^#' | \ + sed '/mksh_cfg.*= *$/{ + N + s/\n/ / + }' | \ grep '^ *mksh_cfg *=' | \ sed 's/^ *mksh_cfg *=[ ]*\([0-9][0-9x]*\).*$/:\1 '$name/ 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 test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN 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 diff --git a/Makefile b/Makefile index e14f564..106506d 100644 --- a/Makefile +++ b/Makefile @@ -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, # 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_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_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+= -I. COPTS+= -std=c89 -Wall diff --git a/check.t b/check.t index 99c2467..aa43e55 100644 --- a/check.t +++ b/check.t @@ -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 #- # 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 expected-stdout: - @(#)MIRBSD KSH R50 2014/11/19 + @(#)MIRBSD KSH R50 2014/11/25 description: Check version of shell. stdin: @@ -36,7 +36,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R50 2014/11/19 + @(#)LEGACY KSH R50 2014/11/25 description: Check version of legacy shell. stdin: @@ -7141,6 +7141,7 @@ description: XXX if the OS can already execute them, 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 + XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan) need-pass: no category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh env-setup: !FOO=BAR! @@ -11060,6 +11061,7 @@ stdin: (mypid=$$; try mypid) echo =15 ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//' + exit ${PIPESTATUS[0]} expected-stdout: y =1 diff --git a/edit.c b/edit.c index 9ab0600..29b48f4 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #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 @@ -593,8 +593,6 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp, char **words = NULL; bool is_command; - mkssert(buf != NULL); - len = x_locate_word(buf, buflen, pos, startp, &is_command); if (!((*flagsp) & XCF_COMMAND)) is_command = false; @@ -2240,7 +2238,6 @@ x_push(int nchars) { char *cp; - mkssert(xcp != NULL); strndupx(cp, xcp, nchars, AEDIT); if (killstack[killsp]) afree(killstack[killsp], AEDIT); diff --git a/eval.c b/eval.c index 7e9d2e5..dbac940 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #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 @@ -237,7 +237,7 @@ expand( /* record number of trailing newlines in COMSUB */ int newlines = 0; bool saw_eq, make_magic; - int tilde_ok; + unsigned int tilde_ok; size_t len; char *cp; @@ -516,7 +516,6 @@ expand( /* check for special cases */ d = str_val(st->var); - mkssert(d != NULL); switch (*pat) { case '#': /* anchor at begin */ diff --git a/exec.c b/exec.c index 34c1259..14207a1 100644 --- a/exec.c +++ b/exec.c @@ -23,7 +23,7 @@ #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 #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -924,11 +924,12 @@ scriptexec(struct op *tp, const char **ap) *tp->args-- = (char *)cp; } noshebang: - if (buf[0] == 0x7F && buf[1] == 'E' && buf[2] == 'L' && - buf[3] == 'F') + cp = (unsigned char *)buf; + if (cp[0] == 0x7F && cp[1] == 'E' && cp[2] == 'L' && + cp[3] == 'F') errorf("%s: not executable: %d-bit ELF file", tp->str, - 32 * ((uint8_t)buf[4])); - fd = buf[0] << 8 | buf[1]; + 32 * cp[4]); + fd = cp[0] << 8 | cp[1]; if ((fd == /* OMAGIC */ 0407) || (fd == /* NMAGIC */ 0410) || (fd == /* ZMAGIC */ 0413) || @@ -1006,8 +1007,6 @@ define(const char *name, struct op *t) while (/* CONSTCOND */ 1) { tp = findfunc(name, nhash, true); - /* because findfunc:create=true */ - mkssert(tp != NULL); if (tp->flag & ISSET) was_set = true; diff --git a/funcs.c b/funcs.c index 5cba10d..f7e5681 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #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 /* @@ -2797,8 +2797,6 @@ c_test(const char **wp) for (argc = 0; wp[argc]; argc++) ; - mkssert(argc > 0); - mkssert(wp[0] != NULL); if (strcmp(wp[0], "[") == 0) { if (strcmp(wp[--argc], "]") != 0) { diff --git a/histrap.c b/histrap.c index e5b60c6..04d391a 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #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]; 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 *c, *cp; - mkssert(cmd != NULL); strdupx(c, cmd, APERM); if ((cp = strchr(c, '\n')) != NULL) *cp = '\0'; diff --git a/jobs.c b/jobs.c index 18179c1..d09adb6 100644 --- a/jobs.c +++ b/jobs.c @@ -23,7 +23,7 @@ #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 #define mksh_killpg killpg @@ -1047,7 +1047,7 @@ j_async(void) static void j_set_async(Job *j) { - Job *jl, *oldest; + Job *jl, *oldest; if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE) remove_job(async_job, "async"); @@ -1084,7 +1084,7 @@ j_set_async(Job *j) static void j_startjob(Job *j) { - Proc *p; + Proc *p; j->flags |= JF_STARTED; for (p = j->proc_list; p->next; p = p->next) @@ -1421,8 +1421,8 @@ j_sigchld(int sig MKSH_A_UNUSED) static void check_job(Job *j) { - int jstate; - Proc *p; + int jstate; + Proc *p; /* XXX debugging (nasty - interrupt routine using shl_out) */ if (!(j->flags & JF_STARTED)) { @@ -1524,14 +1524,14 @@ check_job(Job *j) static void j_print(Job *j, int how, struct shf *shf) { - Proc *p; - int state; - int status; - int coredumped; - char jobchar = ' '; - char buf[64]; + Proc *p; + int state; + int status; + int coredumped; + char jobchar = ' '; + char buf[64]; const char *filler; - int output = 0; + int output = 0; if (how == JP_PGRP) { /* @@ -1737,8 +1737,8 @@ static Proc *free_procs; static Job * new_job(void) { - int i; - Job *newj, *j; + int i; + Job *newj, *j; if (free_jobs != NULL) { newj = free_jobs; @@ -1766,7 +1766,7 @@ new_job(void) static Proc * new_proc(void) { - Proc *p; + Proc *p; if (free_procs != NULL) { p = free_procs; @@ -1786,10 +1786,9 @@ new_proc(void) static void remove_job(Job *j, const char *where) { - Proc *p, *tmp; - Job **prev, *curr; + Proc *p, *tmp; + Job **prev, *curr; - mkssert(j != NULL); prev = &job_list; curr = job_list; while (curr && curr != j) { @@ -1830,9 +1829,8 @@ remove_job(Job *j, const char *where) static void put_job(Job *j, int where) { - Job **prev, *curr; + Job **prev, *curr; - mkssert(j != NULL); /* Remove job from list (if there) */ prev = &job_list; curr = job_list; @@ -1869,8 +1867,8 @@ put_job(Job *j, int where) static int kill_job(Job *j, int sig) { - Proc *p; - int rval = 0; + Proc *p; + int rval = 0; for (p = j->proc_list; p != NULL; p = p->next) if (p->pid != 0) diff --git a/main.c b/main.c index 3d659ca..6a5c191 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #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; @@ -1014,8 +1014,6 @@ cleanup_parents_env(void) struct env *ep; int fd; - mkssert(e != NULL); - /* * Don't clean up temporary files - parent will probably need them. * Also, can't easily reclaim memory since variables, etc. could be diff --git a/misc.c b/misc.c index 0aa285b..c6456aa 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #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 #ifdef MKSH_SMALL @@ -485,7 +485,6 @@ parse_args(const char **argv, if (arrayset) { const char *ccp = NULL; - mkssert(array != NULL); if (*array) ccp = skip_varname(array, false); if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) { diff --git a/sh.h b/sh.h index 6777aaf..d7deba5 100644 --- a/sh.h +++ b/sh.h @@ -169,9 +169,9 @@ #endif #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 -#define MKSH_VERSION "R50 2014/11/19" +#define MKSH_VERSION "R50 2014/11/25" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -533,7 +533,7 @@ char *ucstrstr(char *, const char *); #define mkssert(e) do { } while (/* CONSTCOND */ 0) #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. extern void thiswillneverbedefinedIhope(void); int diff --git a/var.c b/var.c index 9f05ec1..7ce9769 100644 --- a/var.c +++ b/var.c @@ -28,7 +28,7 @@ #include #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 @@ -308,7 +308,6 @@ local(const char *n, bool copy) * dereference namerefs; must come first */ n = array_index_calc(n, &array, &val); - mkssert(n != NULL); h = hash(n); if (!ksh_isalphx(*n)) { vp = &vtemp; @@ -679,8 +678,6 @@ exportprep(struct tbl *vp, const char *val) char *op = (vp->flag&ALLOC) ? vp->val.s : NULL; size_t namelen, vallen; - mkssert(val != NULL); - namelen = strlen(vp->name); vallen = strlen(val) + 1;