* @brief Compute the product of two sizes. * * This function is implemented to indicate if overflow has occurred, which may * occur when input values are not trusted. Implementation is obviously slower * than one that does not do this, so don't use for values we know cannot * overflow. * * Overflow signaling is sticky, so calling code can check at the end of a * sequence of multiplies. *
| 491 | * @return The multiplication result, which may have overflowed. |
| 492 | */ |
| 493 | static inline size_t mul_safe( |
| 494 | size_t val_a, |
| 495 | size_t val_b, |
| 496 | bool& overflow |
| 497 | ) { |
| 498 | size_t result = val_a * val_b; |
| 499 | overflow = overflow || ((val_b != 0) && ((result / val_b) != val_a)); |
| 500 | return result; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * @brief Get the number of blocks along a single axis. |
no outgoing calls
no test coverage detected