fix Coverity CID #8, #9

it's wrong to use strchr(s, 0) to look for the NUL byte, because in some
environments it apparently might return NULL

use new macro strnul = s+strlen(s) instead (not side-effect safe tho)
This commit is contained in:
tg
2007-05-13 19:14:05 +00:00
parent 655b50a7d1
commit a84655e3e0
3 changed files with 10 additions and 7 deletions

8
eval.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.26 2007/05/13 17:51:21 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.27 2007/05/13 19:14:04 tg Exp $");
#ifdef MKSH_SMALL
#define MKSH_NOPWNAM
@ -232,7 +232,7 @@ expand(const char *cp, /* input word */
type = comsub(&x, sp);
if (type == XCOM && (f&DOBLANK))
doblank++;
sp = cstrchr(sp, 0) + 1;
sp = strnul(sp) + 1;
newlines = 0;
}
continue;
@ -255,7 +255,7 @@ expand(const char *cp, /* input word */
v.name[0] = '\0';
v_evaluate(&v, substitute(sp, 0),
KSH_UNWIND_ERROR, true);
sp = cstrchr(sp, 0) + 1;
sp = strnul(sp) + 1;
for (p = str_val(&v); *p; ) {
Xcheck(ds, dp);
*dp++ = *p++;
@ -891,7 +891,7 @@ comsub(Expand *xp, const char *cp)
static char *
trimsub(char *str, char *pat, int how)
{
char *end = strchr(str, 0);
char *end = strnul(str);
char *p, c;
switch (how&0xff) { /* UCHAR_MAX maybe? */