Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
safe-math.h
1/* Overflow-safe math helper macros
2 *
3 * To the extent possible under law, the authors have waived all
4 * copyright and related or neighboring rights to this code. For
5 * details, see the Creative Commons Zero 1.0 Universal license at
6 * https://creativecommons.org/publicdomain/zero/1.0/
7 */
8
9#pragma once
10
11#include <setjmp.h>
12
13#define ws_safe_op_jmp(op, res, a, b, env) \
14 do { \
15 if(ckd_##op(res, a, b)) { \
16 longjmp(env, 1); \
17 } \
18 } while (0)
19
20#define ws_safe_add_jmp(res, a, b, env) ws_safe_op_jmp(add, res, a, b, env)
21#define ws_safe_sub_jmp(res, a, b, env) ws_safe_op_jmp(sub, res, a, b, env)
22#define ws_safe_mul_jmp(res, a, b, env) ws_safe_op_jmp(mul, res, a, b, env)