aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-08-02 05:02:46 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-08-02 05:02:46 +0000
commitf4eebef50a14b8f804aed9a13f6437c6550b348e (patch)
treebf2c45a12020be4e0a37547abb50c40c0074e8ec /libbb
parentdcfdcb7f829849a4b6d14b162cfab8e7c381fd2f (diff)
downloadbusybox-w32-f4eebef50a14b8f804aed9a13f6437c6550b348e.tar.gz
busybox-w32-f4eebef50a14b8f804aed9a13f6437c6550b348e.tar.bz2
busybox-w32-f4eebef50a14b8f804aed9a13f6437c6550b348e.zip
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. git-svn-id: svn://busybox.net/trunk/busybox@3181 69ca8d6d-28ef-0310-b511-8ec308f3f277
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)
119 NUMPTR[-1] = (NUMPTR[-1] <= *NUMPTR); 119 NUMPTR[-1] = (NUMPTR[-1] <= *NUMPTR);
120 else if (op == TOK_MUL) 120 else if (op == TOK_MUL)
121 NUMPTR[-1] *= *NUMPTR; 121 NUMPTR[-1] *= *NUMPTR;
122 else if (op == TOK_DIV) 122 else if (op == TOK_DIV) {
123 if(*NUMPTR==0)
124 return -2;
123 NUMPTR[-1] /= *NUMPTR; 125 NUMPTR[-1] /= *NUMPTR;
124 else if (op == TOK_REM) 126 }
127 else if (op == TOK_REM) {
128 if(*NUMPTR==0)
129 return -2;
125 NUMPTR[-1] %= *NUMPTR; 130 NUMPTR[-1] %= *NUMPTR;
131 }
126 else if (op == TOK_ADD) 132 else if (op == TOK_ADD)
127 NUMPTR[-1] += *NUMPTR; 133 NUMPTR[-1] += *NUMPTR;
128 else if (op == TOK_SUB) 134 else if (op == TOK_SUB)
129 NUMPTR[-1] -= *NUMPTR; 135 NUMPTR[-1] -= *NUMPTR;
130 } 136 }
131 return 0; 137 return 0;
132err: return(1); 138err: return(-1);
133} 139}
134 140
135extern long arith (const char *startbuf) 141extern long arith (const char *startbuf, int *errcode)
136{ 142{
137 register char arithval; 143 register char arithval;
138 const char *expr = startbuf; 144 const char *expr = startbuf;
@@ -142,8 +148,9 @@ extern long arith (const char *startbuf)
142 unsigned char prec; 148 unsigned char prec;
143 149
144 long *numstack, *numstackptr; 150 long *numstack, *numstackptr;
145
146 operator *stack = alloca(datasizes * sizeof(operator)), *stackptr = stack; 151 operator *stack = alloca(datasizes * sizeof(operator)), *stackptr = stack;
152
153 *errcode = 0;
147 numstack = alloca((datasizes/2+1)*sizeof(long)), numstackptr = numstack; 154 numstack = alloca((datasizes/2+1)*sizeof(long)), numstackptr = numstack;
148 155
149 while ((arithval = *expr)) { 156 while ((arithval = *expr)) {
@@ -163,7 +170,8 @@ extern long arith (const char *startbuf)
163 op = *--stackptr; 170 op = *--stackptr;
164 if (op == TOK_LPAREN) 171 if (op == TOK_LPAREN)
165 goto prologue; 172 goto prologue;
166 if(ARITH_APPLY(op)) goto err; 173 *errcode = ARITH_APPLY(op);
174 if(*errcode) return *errcode;
167 } 175 }
168 goto err; /* Mismatched parens */ 176 goto err; /* Mismatched parens */
169 } if (arithval == '|') { 177 } if (arithval == '|') {
@@ -231,17 +239,22 @@ extern long arith (const char *startbuf)
231 239
232 prec = PREC(op); 240 prec = PREC(op);
233 if (prec != UNARYPREC) 241 if (prec != UNARYPREC)
234 while (stackptr != stack && PREC(stackptr[-1]) >= prec) 242 while (stackptr != stack && PREC(stackptr[-1]) >= prec) {
235 if(ARITH_APPLY(*--stackptr)) goto err; 243 *errcode = ARITH_APPLY(*--stackptr);
244 if(*errcode) return *errcode;
245 }
236 *stackptr++ = op; 246 *stackptr++ = op;
237 lasttok = op; 247 lasttok = op;
238prologue: ++expr; 248prologue: ++expr;
239 } /* yay */ 249 } /* yay */
240 250
241 while (stackptr != stack) 251 while (stackptr != stack) {
242 if(ARITH_APPLY(*--stackptr)) goto err; 252 *errcode = ARITH_APPLY(*--stackptr);
253 if(*errcode) return *errcode;
254 }
243 if (numstackptr != numstack+1) { 255 if (numstackptr != numstack+1) {
244err: 256err:
257 *errcode = -1;
245 return -1; 258 return -1;
246 /* NOTREACHED */ 259 /* NOTREACHED */
247 } 260 }
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)
17 if (!path) 17 if (!path)
18 path=""; 18 path="";
19 lc = last_char_is(path, '/'); 19 lc = last_char_is(path, '/');
20 if (filename[0] == '/') 20 while (*filename == '/')
21 filename++; 21 filename++;
22 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); 22 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
23 sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename); 23 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);
212char *concat_path_file(const char *path, const char *filename); 212char *concat_path_file(const char *path, const char *filename);
213char *last_char_is(const char *s, int c); 213char *last_char_is(const char *s, int c);
214 214
215extern long arith (const char *startbuf); 215extern long arith (const char *startbuf, int *errcode);
216 216
217typedef struct file_headers_s { 217typedef struct file_headers_s {
218 char *name; 218 char *name;
@@ -261,6 +261,8 @@ char *dirname (const char *path);
261 261
262int make_directory (char *path, mode_t mode, int flags); 262int make_directory (char *path, mode_t mode, int flags);
263 263
264const char *u_signal_names(const char *str_sig, int *signo, int startnum);
265
264#define CT_AUTO 0 266#define CT_AUTO 0
265#define CT_UNIX2DOS 1 267#define CT_UNIX2DOS 1
266#define CT_DOS2UNIX 2 268#define CT_DOS2UNIX 2