I've tried to make every effort to remove the possibility of undefined * behavior and prevent related errors where maliciously crafted files could * lead to buffer overflows or the like. To that end, we'll start with some * functions that check various operations for behaving as expected. This one * returns nonzero if the two size_ts can be added without wrapping, or 0 if * the result would
| 64 | * the result would wrap. |
| 65 | */ |
| 66 | static int CanAdd(size_t a, size_t b) |
| 67 | { |
| 68 | return a <= SIZE_MAX - b; |
| 69 | } |
| 70 | |
| 71 | /* Returns nonzero if the two size_ts can be multiplied without wrapping, or 0 |
| 72 | * if the result would wrap. b must not be 0 (we don't even check here since |