patch most of Jerker Bäck’s concerns out, unless not applicable

This commit is contained in:
tg
2011-08-27 18:06:52 +00:00
parent 5d9c88ceeb
commit 577c918beb
18 changed files with 408 additions and 324 deletions

33
var.c
View File

@ -26,7 +26,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.130 2011/07/07 20:24:53 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.131 2011/08/27 18:06:52 tg Exp $");
/*-
* Variables
@ -170,7 +170,7 @@ static const char *
array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
{
const char *p;
int len;
size_t len;
char *ap = NULL;
*arrayp = false;
@ -585,7 +585,7 @@ formatstr(struct tbl *vp, const char *s)
char *p, *q;
size_t psiz;
olen = utf_mbswidth(s);
olen = (int)utf_mbswidth(s);
if (vp->flag & (RJUST|LJUST)) {
if (!vp->u2.field)
@ -693,7 +693,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
struct tbl *vpbase, *t;
char *tvar;
const char *val;
int len;
size_t len;
bool vappend = false;
/* check for valid variable name, search for value */
@ -717,7 +717,8 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
* would be a major security hole.
*/
if (set & IMPORT) {
int i;
size_t i;
for (i = 1; i < len - 1; i++)
if (!ksh_isdigit(val[i]))
return (NULL);
@ -738,9 +739,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
val = NULL;
/* handle foo[*] => foo (whole array) mapping for R39b */
len = strlen(tvar);
if (len > 3 && tvar[len-3] == '[' && tvar[len-2] == '*' &&
tvar[len-1] == ']')
tvar[len-3] = '\0';
if (len > 3 && tvar[len - 3] == '[' && tvar[len - 2] == '*' &&
tvar[len - 1] == ']')
tvar[len - 3] = '\0';
}
if (set_refflag == SRF_ENABLE) {
@ -944,7 +945,7 @@ unset(struct tbl *vp, int flags)
const char *
skip_varname(const char *s, int aok)
{
int alen;
size_t alen;
if (s && ksh_isalphx(*s)) {
while (*++s && ksh_isalnux(*s))
@ -1336,11 +1337,11 @@ arraysearch(struct tbl *vp, uint32_t val)
* to point to the open bracket. Returns 0 if there is no matching
* closing bracket.
*/
int
size_t
array_ref_len(const char *cp)
{
const char *s = cp;
int c;
char c;
int depth = 0;
while ((c = *s++) && (c != ']' || --depth))
@ -1374,19 +1375,20 @@ mksh_uari_t
set_array(const char *var, bool reset, const char **vals)
{
struct tbl *vp, *vq;
mksh_uari_t i, j = 0;
mksh_uari_t i = 0, j = 0;
const char *ccp;
#ifndef MKSH_SMALL
char *cp = NULL;
size_t n;
#endif
/* to get local array, use "typeset foo; set -A foo" */
#ifndef MKSH_SMALL
i = strlen(var);
if (i > 0 && var[i - 1] == '+') {
n = strlen(var);
if (n > 0 && var[n - 1] == '+') {
/* append mode */
reset = false;
strndupx(cp, var, i - 1, ATEMP);
strndupx(cp, var, n - 1, ATEMP);
}
#define CPORVAR (cp ? cp : var)
#else
@ -1406,7 +1408,6 @@ set_array(const char *var, bool reset, const char **vals)
* completely fail. Only really effects integer arrays:
* evaluation of some of vals[] may fail...
*/
i = 0;
#ifndef MKSH_SMALL
if (cp != NULL) {
/* find out where to set when appending */