diff options
author | Kees Cook <keescook@chromium.org> | 2024-01-18 16:05:52 -0800 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2024-02-29 13:38:01 -0800 |
commit | d70de8054c58d7bd9a4654c9f4797d29fa46d545 (patch) | |
tree | bcc66c9026a9407845dca2827111bf619c092626 /lib/string_helpers.c | |
parent | 3e19086fb5a9079611de426e8cb2f4503e28757e (diff) |
overflow: Introduce wrapping_add(), wrapping_sub(), and wrapping_mul()
Provide helpers that will perform wrapping addition, subtraction, or
multiplication without tripping the arithmetic wrap-around sanitizers. The
first argument is the type under which the wrap-around should happen
with. In other words, these two calls will get very different results:
wrapping_mul(int, 50, 50) == 2500
wrapping_mul(u8, 50, 50) == 196
Add to the selftests to validate behavior and lack of side-effects.
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Marco Elver <elver@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'lib/string_helpers.c')
0 files changed, 0 insertions, 0 deletions