aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-08-02 05:02:46 +0000
committerEric Andersen <andersen@codepoet.org>2001-08-02 05:02:46 +0000
commit34506361697643277042fc8d7294bc17a27d4e28 (patch)
treebf2c45a12020be4e0a37547abb50c40c0074e8ec /libbb
parent2d91deba45d5a284614e06cc55e2be03599ca26d (diff)
downloadbusybox-34506361697643277042fc8d7294bc17a27d4e28.tar.gz
Latest patch from vodz. Adds a check for divide by zero in the posix
math suport, cleaner math syntax error checking, moves redundant signal string tables (from kill and ash) into libbb and provides a few cleanups elsewhere.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/arith.c33
-rw-r--r--libbb/concat_path_file.c2
-rw-r--r--libbb/libbb.h4
3 files changed, 27 insertions, 12 deletions
diff --git a/libbb/arith.c b/libbb/arith.c
index c7a3cf98b..04c45ec3d 100644
--- a/libbb/arith.c
+++ b/libbb/arith.c
@@ -119,20 +119,26 @@ static short arith_apply(operator op, long *numstack, long **numstackptr)
NUMPTR[-1] = (NUMPTR[-1] <= *NUMPTR);
else if (op == TOK_MUL)
NUMPTR[-1] *= *NUMPTR;
- else if (op == TOK_DIV)
+ else if (op == TOK_DIV) {
+ if(*NUMPTR==0)
+ return -2;
NUMPTR[-1] /= *NUMPTR;
- else if (op == TOK_REM)
+ }
+ else if (op == TOK_REM) {
+ if(*NUMPTR==0)
+ return -2;
NUMPTR[-1] %= *NUMPTR;
+ }
else if (op == TOK_ADD)
NUMPTR[-1] += *NUMPTR;
else if (op == TOK_SUB)
NUMPTR[-1] -= *NUMPTR;
}
return 0;
-err: return(1);
+err: return(-1);
}
-extern long arith (const char *startbuf)
+extern long arith (const char *startbuf, int *errcode)
{
register char arithval;
const char *expr = startbuf;
@@ -142,8 +148,9 @@ extern long arith (const char *startbuf)
unsigned char prec;
long *numstack, *numstackptr;
-
operator *stack = alloca(datasizes * sizeof(operator)), *stackptr = stack;
+
+ *errcode = 0;
numstack = alloca((datasizes/2+1)*sizeof(long)), numstackptr = numstack;
while ((arithval = *expr)) {
@@ -163,7 +170,8 @@ extern long arith (const char *startbuf)
op = *--stackptr;
if (op == TOK_LPAREN)
goto prologue;
- if(ARITH_APPLY(op)) goto err;
+ *errcode = ARITH_APPLY(op);
+ if(*errcode) return *errcode;
}
goto err; /* Mismatched parens */
} if (arithval == '|') {
@@ -231,17 +239,22 @@ extern long arith (const char *startbuf)
prec = PREC(op);
if (prec != UNARYPREC)
- while (stackptr != stack && PREC(stackptr[-1]) >= prec)
- if(ARITH_APPLY(*--stackptr)) goto err;
+ while (stackptr != stack && PREC(stackptr[-1]) >= prec) {
+ *errcode = ARITH_APPLY(*--stackptr);
+ if(*errcode) return *errcode;
+ }
*stackptr++ = op;
lasttok = op;
prologue: ++expr;
} /* yay */
- while (stackptr != stack)
- if(ARITH_APPLY(*--stackptr)) goto err;
+ while (stackptr != stack) {
+ *errcode = ARITH_APPLY(*--stackptr);
+ if(*errcode) return *errcode;
+ }
if (numstackptr != numstack+1) {
err:
+ *errcode = -1;
return -1;
/* NOTREACHED */
}
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index c699a84f7..86dd2fbbf 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -17,7 +17,7 @@ extern char *concat_path_file(const char *path, const char *filename)
if (!path)
path="";
lc = last_char_is(path, '/');
- if (filename[0] == '/')
+ while (*filename == '/')
filename++;
outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 66acc2278..df52027ce 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -212,7 +212,7 @@ char *xreadlink(const char *path);
char *concat_path_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c);
-extern long arith (const char *startbuf);
+extern long arith (const char *startbuf, int *errcode);
typedef struct file_headers_s {
char *name;
@@ -261,6 +261,8 @@ char *dirname (const char *path);
int make_directory (char *path, mode_t mode, int flags);
+const char *u_signal_names(const char *str_sig, int *signo, int startnum);
+
#define CT_AUTO 0
#define CT_UNIX2DOS 1
#define CT_DOS2UNIX 2