Changeset 34 for trunk/src/slib.c
- Timestamp:
- May 19, 2006, 8:09:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r29 r34 7 7 #include <string.h> 8 8 #include <limits.h> 9 #ifdef HAVE_STDINT_H 10 /* for SIZE_MAX */ 11 #include <stdint.h> 12 #endif 9 13 10 14 #include <unistd.h> … … 2506 2510 * ---------------------------------------------------------------- */ 2507 2511 2512 #ifndef SIZE_MAX 2513 #define SIZE_MAX (4294967295U) 2514 #endif 2515 2508 2516 int sl_ok_muli (int a, int b) /* a*b */ 2509 2517 { 2510 if (a >= (INT_MIN / b) && a <= (INT_MAX / b)) 2518 if ((b == 0) || (a >= (INT_MIN / b) && a <= (INT_MAX / b))) 2519 return SL_TRUE; /* no overflow */ 2520 return SL_FALSE; 2521 } 2522 2523 int sl_ok_muls (size_t a, size_t b) /* a*b */ 2524 { 2525 if ((b == 0) || (a <= (SIZE_MAX / b))) 2511 2526 return SL_TRUE; /* no overflow */ 2512 2527 return SL_FALSE; … … 2540 2555 } 2541 2556 2557 int sl_ok_adds (size_t a, size_t b) /* a+b */ 2558 { 2559 if (a <= (SIZE_MAX - b)) 2560 return SL_TRUE; /* no overflow */ 2561 else 2562 return SL_FALSE; 2563 } 2564 2542 2565 int sl_ok_subi (int a, int b) /* a-b */ 2543 2566 {
Note:
See TracChangeset
for help on using the changeset viewer.