• syn.c: replace expanded use of str_save() with the actual macro
• others: fix 6 (!) cases of non-constant or side-effect arguments to the str_save() or str_nsave() macros, and other abuse of them • also fix some cosmetics and other un-nice code while here
This commit is contained in:
		
							
								
								
									
										10
									
								
								eval.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								eval.c
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.46 2008/05/17 18:46:58 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.47 2008/07/12 16:56:38 tg Exp $");
 | 
			
		||||
 | 
			
		||||
#ifdef MKSH_SMALL
 | 
			
		||||
#define MKSH_NOPWNAM
 | 
			
		||||
@@ -425,7 +425,8 @@ expand(const char *cp,	/* input word */
 | 
			
		||||
							goto no_repl;
 | 
			
		||||
 | 
			
		||||
						/* prepare string on which to work */
 | 
			
		||||
						sbeg = s = str_save(str_val(st->var), ATEMP);
 | 
			
		||||
						tpat0 = str_val(st->var);
 | 
			
		||||
						sbeg = s = str_save(tpat0, ATEMP);
 | 
			
		||||
 | 
			
		||||
						/* first see if we have any match at all */
 | 
			
		||||
						tpat0 = pat;
 | 
			
		||||
@@ -769,10 +770,7 @@ expand(const char *cp,	/* input word */
 | 
			
		||||
				    Xlength(ds, dp) == 0) {
 | 
			
		||||
					char *p;
 | 
			
		||||
 | 
			
		||||
					if ((p = str_nsave(null, 0, ATEMP))
 | 
			
		||||
					    == NULL)
 | 
			
		||||
						internal_errorf("unable "
 | 
			
		||||
						    "to allocate memory");
 | 
			
		||||
					*(p = alloc(1, ATEMP)) = '\0';
 | 
			
		||||
					XPput(*wp, p);
 | 
			
		||||
				}
 | 
			
		||||
				type = XSUBMID;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								expr.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								expr.c
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.17 2008/04/20 00:24:25 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.18 2008/07/12 16:56:38 tg Exp $");
 | 
			
		||||
 | 
			
		||||
/* The order of these enums is constrained by the order of opinfo[] */
 | 
			
		||||
enum token {
 | 
			
		||||
@@ -480,9 +480,12 @@ exprtoken(Expr_state *es)
 | 
			
		||||
		tvar = str_nsave(es->tokp, cp - es->tokp, ATEMP);
 | 
			
		||||
		goto process_tvar;
 | 
			
		||||
	} else if (ksh_isdigit(c)) {
 | 
			
		||||
		int i;
 | 
			
		||||
 | 
			
		||||
		while (c != '_' && (ksh_isalnux(c) || c == '#'))
 | 
			
		||||
			c = *cp++;
 | 
			
		||||
		tvar = str_nsave(es->tokp, --cp - es->tokp, ATEMP);
 | 
			
		||||
		i = --cp - es->tokp;
 | 
			
		||||
		tvar = str_nsave(es->tokp, i, ATEMP);
 | 
			
		||||
 process_tvar:
 | 
			
		||||
		es->val = tempvar();
 | 
			
		||||
		es->val->flag &= ~INTEGER;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								funcs.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								funcs.c
									
									
									
									
									
								
							@@ -5,7 +5,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.83 2008/06/08 17:16:25 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.84 2008/07/12 16:56:39 tg Exp $");
 | 
			
		||||
 | 
			
		||||
/* A leading = means assignments before command are kept;
 | 
			
		||||
 * a leading * means a POSIX special builtin;
 | 
			
		||||
@@ -1074,8 +1074,10 @@ c_alias(const char **wp)
 | 
			
		||||
		struct tbl *ap;
 | 
			
		||||
		int h;
 | 
			
		||||
 | 
			
		||||
		if ((val = cstrchr(alias, '=')))
 | 
			
		||||
			alias = xalias = str_nsave(alias, val++ - alias, ATEMP);
 | 
			
		||||
		if ((val = cstrchr(alias, '='))) {
 | 
			
		||||
			h = val++ - alias;
 | 
			
		||||
			alias = xalias = str_nsave(alias, h, ATEMP);
 | 
			
		||||
		}
 | 
			
		||||
		h = hash(alias);
 | 
			
		||||
		if (val == NULL && !tflag && !xflag) {
 | 
			
		||||
			ap = ktsearch(t, alias, h);
 | 
			
		||||
@@ -1103,8 +1105,7 @@ c_alias(const char **wp)
 | 
			
		||||
				afree((void*)ap->val.s, APERM);
 | 
			
		||||
			}
 | 
			
		||||
			/* ignore values for -t (at&t ksh does this) */
 | 
			
		||||
			newval = tflag ? search(alias, path, X_OK, NULL) :
 | 
			
		||||
			    val;
 | 
			
		||||
			newval = tflag ? search(alias, path, X_OK, NULL) : val;
 | 
			
		||||
			if (newval) {
 | 
			
		||||
				ap->val.s = str_save(newval, APERM);
 | 
			
		||||
				ap->flag |= ALLOC|ISSET;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								histrap.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								histrap.c
									
									
									
									
									
								
							@@ -3,7 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.65 2008/07/06 22:41:08 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.66 2008/07/12 16:56:39 tg Exp $");
 | 
			
		||||
 | 
			
		||||
/*-
 | 
			
		||||
 * MirOS: This is the default mapping type, and need not be specified.
 | 
			
		||||
@@ -21,7 +21,7 @@ static int hist_count_lines(unsigned char *, int);
 | 
			
		||||
static int hist_shrink(unsigned char *, int);
 | 
			
		||||
static unsigned char *hist_skip_back(unsigned char *,int *,int);
 | 
			
		||||
static void histload(Source *, unsigned char *, int);
 | 
			
		||||
static void histinsert(Source *, int, unsigned char *);
 | 
			
		||||
static void histinsert(Source *, int, const char *);
 | 
			
		||||
static void writehistfile(int, char *);
 | 
			
		||||
static int sprinkle(int);
 | 
			
		||||
#endif
 | 
			
		||||
@@ -68,7 +68,8 @@ c_fc(const char **wp)
 | 
			
		||||
				sflag++;
 | 
			
		||||
			else {
 | 
			
		||||
				size_t len = strlen(p);
 | 
			
		||||
				editor = str_nsave(p, len + 4, ATEMP);
 | 
			
		||||
				editor = alloc(len + 4, ATEMP);
 | 
			
		||||
				memcpy(editor, p, len);
 | 
			
		||||
				memcpy(editor + len, " $_", 4);
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
@@ -639,8 +640,7 @@ hist_init(Source *s)
 | 
			
		||||
	hist_source = s;
 | 
			
		||||
 | 
			
		||||
#if HAVE_PERSISTENT_HISTORY
 | 
			
		||||
	hname = str_val(global("HISTFILE"));
 | 
			
		||||
	if (hname == NULL)
 | 
			
		||||
	if ((hname = str_val(global("HISTFILE"))) == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
	hname = str_save(hname, APERM);
 | 
			
		||||
 | 
			
		||||
@@ -855,7 +855,7 @@ histload(Source *s, unsigned char *base, int bytes)
 | 
			
		||||
				/* worry about line numbers */
 | 
			
		||||
				if (histptr >= history && lno-1 != s->line) {
 | 
			
		||||
					/* a replacement ? */
 | 
			
		||||
					histinsert(s, lno, line);
 | 
			
		||||
					histinsert(s, lno, (char *)line);
 | 
			
		||||
				} else {
 | 
			
		||||
					s->line = lno;
 | 
			
		||||
					histsave(lno, (char *)line, 0);
 | 
			
		||||
@@ -870,15 +870,15 @@ histload(Source *s, unsigned char *base, int bytes)
 | 
			
		||||
 *	Insert a line into the history at a specified number
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
histinsert(Source *s, int lno, unsigned char *line)
 | 
			
		||||
histinsert(Source *s, int lno, const char *line)
 | 
			
		||||
{
 | 
			
		||||
	char **hp;
 | 
			
		||||
 | 
			
		||||
	if (lno >= s->line-(histptr-history) && lno <= s->line) {
 | 
			
		||||
		hp = &histptr[lno-s->line];
 | 
			
		||||
	if (lno >= s->line - (histptr - history) && lno <= s->line) {
 | 
			
		||||
		hp = &histptr[lno - s->line];
 | 
			
		||||
		if (*hp)
 | 
			
		||||
			afree((void*)*hp, APERM);
 | 
			
		||||
		*hp = str_save((char *)line, APERM);
 | 
			
		||||
		*hp = str_save(line, APERM);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1005,9 +1005,8 @@ inittraps(void)
 | 
			
		||||
			else {
 | 
			
		||||
				char *s;
 | 
			
		||||
 | 
			
		||||
				sigtraps[i].name = s = str_save(
 | 
			
		||||
				    !strncasecmp(cs, "SIG", 3) ? cs + 3 : cs,
 | 
			
		||||
				    APERM);
 | 
			
		||||
				s = !strncasecmp(cs, "SIG", 3) ? cs + 3 : cs;
 | 
			
		||||
				sigtraps[i].name = s = str_save(s, APERM);
 | 
			
		||||
				while ((*s = ksh_toupper(*s)))
 | 
			
		||||
					++s;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								lex.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								lex.c
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.65 2008/07/09 21:32:43 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.66 2008/07/12 16:56:39 tg Exp $");
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * states while lexing word
 | 
			
		||||
@@ -1290,9 +1290,10 @@ set_prompt(int to, Source *s)
 | 
			
		||||
				 * unwinding its stack through this code as it
 | 
			
		||||
				 * exits.
 | 
			
		||||
				 */
 | 
			
		||||
			} else
 | 
			
		||||
				prompt = str_save(substitute(ps1, 0),
 | 
			
		||||
				    saved_atemp);
 | 
			
		||||
			} else {
 | 
			
		||||
				char *cp = substitute(ps1, 0);
 | 
			
		||||
				prompt = str_save(cp, saved_atemp);
 | 
			
		||||
			}
 | 
			
		||||
			quitenv(NULL);
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								syn.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								syn.c
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.22 2008/06/28 22:51:56 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.23 2008/07/12 16:56:40 tg Exp $");
 | 
			
		||||
 | 
			
		||||
struct nesting_state {
 | 
			
		||||
	int start_token;	/* token than began nesting (eg, FOR) */
 | 
			
		||||
@@ -366,7 +366,7 @@ get_command(int cf)
 | 
			
		||||
		if (!is_wdvarname(yylval.cp, true))
 | 
			
		||||
			yyerror("%s: bad identifier\n",
 | 
			
		||||
			    c == FOR ? "for" : "select");
 | 
			
		||||
		t->str = str_nsave(ident, strlen(ident), ATEMP);
 | 
			
		||||
		t->str = str_save(ident, ATEMP);
 | 
			
		||||
		nesting_push(&old_nesting, c);
 | 
			
		||||
		t->vars = wordlist();
 | 
			
		||||
		t->left = dogroup();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								var.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								var.c
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "sh.h"
 | 
			
		||||
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.56 2008/05/17 18:47:03 tg Exp $");
 | 
			
		||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.57 2008/07/12 16:56:40 tg Exp $");
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Variables
 | 
			
		||||
@@ -130,7 +130,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
 | 
			
		||||
 | 
			
		||||
		/* Calculate the value of the subscript */
 | 
			
		||||
		*arrayp = true;
 | 
			
		||||
		tmp = str_nsave(p+1, len-2, ATEMP);
 | 
			
		||||
		tmp = str_nsave(p + 1, len - 2, ATEMP);
 | 
			
		||||
		sub = substitute(tmp, 0);
 | 
			
		||||
		afree(tmp, ATEMP);
 | 
			
		||||
		n = str_nsave(n, p - n, ATEMP);
 | 
			
		||||
@@ -642,9 +642,10 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
 | 
			
		||||
		}
 | 
			
		||||
		val += len;
 | 
			
		||||
	}
 | 
			
		||||
	if (*val == '=')
 | 
			
		||||
		tvar = str_nsave(var, val++ - var, ATEMP);
 | 
			
		||||
	else {
 | 
			
		||||
	if (*val == '=') {
 | 
			
		||||
		int i = val++ - var;
 | 
			
		||||
		tvar = str_nsave(var, i, ATEMP);
 | 
			
		||||
	} else {
 | 
			
		||||
		/* Importing from original environment: must have an = */
 | 
			
		||||
		if (set & IMPORT)
 | 
			
		||||
			return NULL;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user