Add assertions and shuffle code around for LLVM+Clang scan-build.
This commit is contained in:
6
check.t
6
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.569 2012/11/30 19:25:01 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.570 2012/12/04 01:18:24 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 R41 2012/11/30
|
@(#)MIRBSD KSH R41 2012/12/03
|
||||||
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 R41 2012/11/30
|
@(#)LEGACY KSH R41 2012/12/03
|
||||||
description:
|
description:
|
||||||
Check version of legacy shell.
|
Check version of legacy shell.
|
||||||
stdin:
|
stdin:
|
||||||
|
3
edit.c
3
edit.c
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.257 2012/12/01 01:36:19 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.258 2012/12/04 01:18:26 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
|
||||||
@ -2273,6 +2273,7 @@ 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);
|
||||||
|
18
exec.c
18
exec.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.107 2012/11/30 20:19:11 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.108 2012/12/04 01:18:27 tg Exp $");
|
||||||
|
|
||||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||||
@ -32,7 +32,7 @@ __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.107 2012/11/30 20:19:11 tg Exp $");
|
|||||||
static int comexec(struct op *, struct tbl * volatile, const char **,
|
static int comexec(struct op *, struct tbl * volatile, const char **,
|
||||||
int volatile, volatile int *);
|
int volatile, volatile int *);
|
||||||
static void scriptexec(struct op *, const char **) MKSH_A_NORETURN;
|
static void scriptexec(struct op *, const char **) MKSH_A_NORETURN;
|
||||||
static int call_builtin(struct tbl *, const char **);
|
static int call_builtin(struct tbl *, const char **, const char *);
|
||||||
static int iosetup(struct ioword *, struct tbl *);
|
static int iosetup(struct ioword *, struct tbl *);
|
||||||
static int herein(const char *, int, char **);
|
static int herein(const char *, int, char **);
|
||||||
static const char *do_selectargs(const char **, bool);
|
static const char *do_selectargs(const char **, bool);
|
||||||
@ -672,7 +672,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||||||
|
|
||||||
/* shell built-in */
|
/* shell built-in */
|
||||||
case CSHELL:
|
case CSHELL:
|
||||||
rv = call_builtin(tp, (const char **)ap);
|
rv = call_builtin(tp, (const char **)ap, null);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* function call */
|
/* function call */
|
||||||
@ -933,9 +933,7 @@ shcomexec(const char **wp)
|
|||||||
struct tbl *tp;
|
struct tbl *tp;
|
||||||
|
|
||||||
tp = ktsearch(&builtins, *wp, hash(*wp));
|
tp = ktsearch(&builtins, *wp, hash(*wp));
|
||||||
if (tp == NULL)
|
return (call_builtin(tp, wp, "shcomexec"));
|
||||||
internal_errorf("%s: %s", "shcomexec", *wp);
|
|
||||||
return (call_builtin(tp, wp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -984,6 +982,8 @@ 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;
|
||||||
@ -1250,10 +1250,12 @@ search_path(const char *name, const char *lpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
call_builtin(struct tbl *tp, const char **wp)
|
call_builtin(struct tbl *tp, const char **wp, const char *where)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
if (!tp)
|
||||||
|
internal_errorf("%s: %s", where, wp[0]);
|
||||||
builtin_argv0 = wp[0];
|
builtin_argv0 = wp[0];
|
||||||
builtin_flag = tp->flag;
|
builtin_flag = tp->flag;
|
||||||
shf_reopen(1, SHF_WR, shl_stdout);
|
shf_reopen(1, SHF_WR, shl_stdout);
|
||||||
@ -1534,7 +1536,7 @@ do_selectargs(const char **ap, bool print_menu)
|
|||||||
if (print_menu || !*str_val(global("REPLY")))
|
if (print_menu || !*str_val(global("REPLY")))
|
||||||
pr_menu(ap);
|
pr_menu(ap);
|
||||||
shellf("%s", str_val(global("PS3")));
|
shellf("%s", str_val(global("PS3")));
|
||||||
if (call_builtin(findcom("read", FC_BI), read_args))
|
if (call_builtin(findcom("read", FC_BI), read_args, Tselect))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
s = str_val(global("REPLY"));
|
s = str_val(global("REPLY"));
|
||||||
if (*s) {
|
if (*s) {
|
||||||
|
9
funcs.c
9
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.231 2012/12/01 01:36:23 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.232 2012/12/04 01:18:28 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -852,8 +852,6 @@ c_typeset(const char **wp)
|
|||||||
} else if (wp[builtin_opt.optind]) {
|
} else if (wp[builtin_opt.optind]) {
|
||||||
for (i = builtin_opt.optind; wp[i]; i++) {
|
for (i = builtin_opt.optind; wp[i]; i++) {
|
||||||
varsearch(e->loc, &vp, wp[i], hash(wp[i]));
|
varsearch(e->loc, &vp, wp[i], hash(wp[i]));
|
||||||
if (!vp)
|
|
||||||
continue;
|
|
||||||
c_typeset_vardump(vp, flag, thing, pflag, istset);
|
c_typeset_vardump(vp, flag, thing, pflag, istset);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -883,6 +881,9 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
|
|||||||
int any_set = 0;
|
int any_set = 0;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
|
if (!vp)
|
||||||
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See if the parameter is set (for arrays, if any
|
* See if the parameter is set (for arrays, if any
|
||||||
* element is set).
|
* element is set).
|
||||||
@ -2765,6 +2766,8 @@ 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) {
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.128 2012/11/30 19:02:07 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.129 2012/12/04 01:18:30 tg Exp $");
|
||||||
|
|
||||||
Trap sigtraps[NSIG + 1];
|
Trap sigtraps[NSIG + 1];
|
||||||
static struct sigaction Sigact_ign;
|
static struct sigaction Sigact_ign;
|
||||||
@ -634,6 +634,7 @@ 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';
|
||||||
|
18
jobs.c
18
jobs.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.91 2012/11/30 19:25:03 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.92 2012/12/04 01:18:31 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
#define mksh_killpg killpg
|
#define mksh_killpg killpg
|
||||||
@ -1722,10 +1722,13 @@ 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 = *prev;
|
curr = job_list;
|
||||||
for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
|
while (curr && curr != j) {
|
||||||
;
|
prev = &curr->next;
|
||||||
|
curr = *prev;
|
||||||
|
}
|
||||||
if (curr != j) {
|
if (curr != j) {
|
||||||
internal_warningf("remove_job: job %s (%s)", "not found", where);
|
internal_warningf("remove_job: job %s (%s)", "not found", where);
|
||||||
return;
|
return;
|
||||||
@ -1762,11 +1765,14 @@ 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;
|
||||||
for (; curr && curr != j; prev = &curr->next, curr = *prev)
|
while (curr && curr != j) {
|
||||||
;
|
prev = &curr->next;
|
||||||
|
curr = *prev;
|
||||||
|
}
|
||||||
if (curr == j)
|
if (curr == j)
|
||||||
*prev = curr->next;
|
*prev = curr->next;
|
||||||
|
|
||||||
|
3
misc.c
3
misc.c
@ -30,7 +30,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.202 2012/12/04 01:12:11 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.203 2012/12/04 01:18:31 tg Exp $");
|
||||||
|
|
||||||
#define KSH_CHVT_FLAG
|
#define KSH_CHVT_FLAG
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
@ -445,6 +445,7 @@ 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]))) {
|
||||||
|
10
sh.h
10
sh.h
@ -152,9 +152,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.611 2012/12/01 01:36:28 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.612 2012/12/04 01:18:32 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R41 2012/11/30"
|
#define MKSH_VERSION "R41 2012/12/03"
|
||||||
|
|
||||||
/* arithmetic types: C implementation */
|
/* arithmetic types: C implementation */
|
||||||
#if !HAVE_CAN_INTTYPES
|
#if !HAVE_CAN_INTTYPES
|
||||||
@ -472,12 +472,16 @@ char *ucstrstr(char *, const char *);
|
|||||||
})
|
})
|
||||||
#define vstrchr(s,c) (cstrchr((s), (c)) != NULL)
|
#define vstrchr(s,c) (cstrchr((s), (c)) != NULL)
|
||||||
#define vstrstr(b,l) (cstrstr((b), (l)) != NULL)
|
#define vstrstr(b,l) (cstrstr((b), (l)) != NULL)
|
||||||
#define mkssert(e) ((e) ? (void)0 : exit(255))
|
|
||||||
#else /* !DEBUG, !gcc */
|
#else /* !DEBUG, !gcc */
|
||||||
#define cstrchr(s,c) ((const char *)strchr((s), (c)))
|
#define cstrchr(s,c) ((const char *)strchr((s), (c)))
|
||||||
#define cstrstr(s,c) ((const char *)strstr((s), (c)))
|
#define cstrstr(s,c) ((const char *)strstr((s), (c)))
|
||||||
#define vstrchr(s,c) (strchr((s), (c)) != NULL)
|
#define vstrchr(s,c) (strchr((s), (c)) != NULL)
|
||||||
#define vstrstr(b,l) (strstr((b), (l)) != NULL)
|
#define vstrstr(b,l) (strstr((b), (l)) != NULL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(DEBUG) || defined(__COVERITY__)
|
||||||
|
#define mkssert(e) ((e) ? (void)0 : exit(255))
|
||||||
|
#else
|
||||||
#define mkssert(e) ((void)0)
|
#define mkssert(e) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
3
var.c
3
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.163 2012/12/04 01:11:17 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.164 2012/12/04 01:18:34 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Variables
|
* Variables
|
||||||
@ -299,6 +299,7 @@ local(const char *n, bool copy)
|
|||||||
|
|
||||||
/* check to see if this is an array */
|
/* check to see if this is an array */
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user