Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/shell/math.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/shell/math.c
r3232 r3621 416 416 else if (right_side_val == 0) 417 417 return "divide by zero"; 418 else if (op == TOK_DIV || op == TOK_DIV_ASSIGN) 419 rez /= right_side_val; 420 else if (op == TOK_REM || op == TOK_REM_ASSIGN) 421 rez %= right_side_val; 418 else if (op == TOK_DIV || op == TOK_DIV_ASSIGN 419 || op == TOK_REM || op == TOK_REM_ASSIGN) { 420 /* 421 * bash 4.2.45 x86 64bit: SEGV on 'echo $((2**63 / -1))' 422 * 423 * MAX_NEGATIVE_INT / -1 = MAX_POSITIVE_INT+1 424 * and thus is not representable. 425 * Some CPUs segfault trying such op. 426 * Others overflow MAX_POSITIVE_INT+1 to 427 * MAX_NEGATIVE_INT (0x7fff+1 = 0x8000). 428 * Make sure to at least not SEGV here: 429 */ 430 if (right_side_val == -1 431 && rez << 1 == 0 /* MAX_NEGATIVE_INT or 0 */ 432 ) { 433 right_side_val = 1; 434 } 435 if (op == TOK_DIV || op == TOK_DIV_ASSIGN) 436 rez /= right_side_val; 437 else { 438 rez %= right_side_val; 439 } 440 } 422 441 } 423 442 … … 495 514 #define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) 496 515 497 const char* FAST_FUNC498 endofname(const char *name)499 {500 if (!is_name(*name))501 return name;502 while (*++name) {503 if (!is_in_name(*name))504 break;505 }506 return name;507 }508 509 516 static arith_t FAST_FUNC 510 517 evaluate_string(arith_state_t *math_state, const char *expr)
Note:
See TracChangeset
for help on using the changeset viewer.