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:
parent
655b50a7d1
commit
a84655e3e0
8
eval.c
8
eval.c
@ -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? */
|
||||
|
4
lex.c
4
lex.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.31 2007/05/13 18:07:22 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.32 2007/05/13 19:14:04 tg Exp $");
|
||||
|
||||
/* Structure to keep track of the lexing state and the various pieces of info
|
||||
* needed for each particular state. */
|
||||
@ -886,7 +886,7 @@ getsc__(void)
|
||||
source->flags |= s->flags & SF_ALIAS;
|
||||
s = source;
|
||||
} else if (*s->u.tblp->val.s &&
|
||||
ksh_isspace(strchr(s->u.tblp->val.s, 0)[-1])) {
|
||||
ksh_isspace(strnul(s->u.tblp->val.s)[-1])) {
|
||||
source = s = s->next; /* pop source stack */
|
||||
/* Note that this alias ended with a space,
|
||||
* enabling alias expansion on the following
|
||||
|
5
sh.h
5
sh.h
@ -8,7 +8,7 @@
|
||||
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
|
||||
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
|
||||
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.130 2007/05/13 18:33:29 tg Exp $"
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.131 2007/05/13 19:14:05 tg Exp $"
|
||||
#define MKSH_VERSION "R29 2007/05/10"
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
@ -323,6 +323,9 @@ char *ucstrstr(char *, const char *);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* use this ipv strchr(s, 0) but no side effects in s! */
|
||||
#define strnul(s) ((s) + strlen(s))
|
||||
|
||||
/*
|
||||
* Area-based allocation built on malloc/free
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user