add a few assertions for LLVM+Clang 3.2 scan-build; no !DEBUG changes

This commit is contained in:
tg 2012-12-08 18:30:31 +00:00
parent c4e88acd83
commit 0780070d24
5 changed files with 55 additions and 6 deletions

4
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.258 2012/12/04 01:18:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.259 2012/12/08 18:30:27 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -607,6 +607,8 @@ 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;

3
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.130 2012/11/30 20:19:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.131 2012/12/08 18:30:29 tg Exp $");
/*
* string expansion
@ -516,6 +516,7 @@ expand(const char *cp, /* input word */
/* check for special cases */
d = str_val(st->var);
mkssert(d != NULL);
switch (*pat) {
case '#':
/* anchor at begin */

27
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.232 2012/12/04 01:18:28 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.233 2012/12/08 18:30:30 tg Exp $");
#if HAVE_KILLPG
/*
@ -2897,6 +2897,31 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
if (!do_eval)
return (0);
#ifdef DEBUG
switch (op) {
/* Binary operators */
case TO_STEQL:
case TO_STNEQ:
case TO_STLT:
case TO_STGT:
case TO_INTEQ:
case TO_INTNE:
case TO_INTGT:
case TO_INTGE:
case TO_INTLT:
case TO_INTLE:
case TO_FILEQ:
case TO_FILNT:
case TO_FILOT:
/* consistency check, but does not happen in practice */
if (!opnd2) {
te->flags |= TEF_ERROR;
return (1);
}
break;
}
#endif
switch (op) {
/*

23
shf.c
View File

@ -24,7 +24,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.49 2012/12/05 19:38:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.50 2012/12/08 18:30:31 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -764,7 +764,12 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
ssize_t field, precision, len;
unsigned long lnum;
/* %#o produces the longest output */
char numbuf[(8 * sizeof(long) + 2) / 3 + 1];
char numbuf[(8 * sizeof(long) + 2) / 3 + 1
#ifdef DEBUG
/* a NUL for LLVM/Clang scan-build */
+ 1
#endif
];
/* this stuff for dealing with the buffer */
ssize_t nwritten = 0;
@ -902,6 +907,16 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
integral:
flags |= FL_NUMBER;
cp = numbuf + sizeof(numbuf);
#ifdef DEBUG
/*
* this is necessary so Clang 3.2 realises
* utf_skipcols/shf_putc in the output loop
* terminate; these values are always ASCII
* so an out-of-bounds access cannot happen
* but Clang doesn't know that
*/
*--cp = '\0';
#endif
switch (c) {
case 'd':
@ -953,6 +968,10 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
}
}
len = numbuf + sizeof(numbuf) - (s = cp);
#ifdef DEBUG
/* see above comment for Clang 3.2 */
--len;
#endif
if (flags & FL_DOT) {
if (precision > len) {
field = precision;

4
var.c
View File

@ -27,7 +27,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.164 2012/12/04 01:18:34 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.165 2012/12/08 18:30:31 tg Exp $");
/*-
* Variables
@ -673,6 +673,8 @@ 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;