* Return a + b if it would not overflow. * Die with an "out of memory" error if it would. */
| 964 | * Die with an "out of memory" error if it would. |
| 965 | */ |
| 966 | static size_t |
| 967 | xadd (size_t a, size_t b) |
| 968 | { |
| 969 | #if defined(__GNUC__) && __GNUC__ >= 5 |
| 970 | size_t result; |
| 971 | if (__builtin_add_overflow (a, b, &result)) |
| 972 | die_oom (); |
| 973 | return result; |
| 974 | #else |
| 975 | if (a > SIZE_MAX - b) |
| 976 | die_oom (); |
| 977 | |
| 978 | return a + b; |
| 979 | #endif |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | * Return a * b if it would not overflow. |
no test coverage detected