42 #include "common.h" |
42 #include "common.h" |
43 |
43 |
44 #ifdef __cplusplus |
44 #ifdef __cplusplus |
45 extern "C" { |
45 extern "C" { |
46 #endif |
46 #endif |
47 |
|
48 // cx_szmul() definition |
|
49 |
|
50 #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN) |
|
51 #define CX_SZMUL_BUILTIN |
|
52 |
|
53 /** |
|
54 * Alias for \c __builtin_mul_overflow. |
|
55 * |
|
56 * Performs a multiplication of size_t values and checks for overflow. |
|
57 * |
|
58 * @param a first operand |
|
59 * @param b second operand |
|
60 * @param result a pointer to a size_t, where the result should |
|
61 * be stored |
|
62 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
63 * otherwise |
|
64 */ |
|
65 #define cx_szmul(a, b, result) __builtin_mul_overflow(a, b, result) |
|
66 |
|
67 #else // no GNUC or clang bultin |
|
68 |
|
69 /** |
|
70 * Performs a multiplication of size_t values and checks for overflow. |
|
71 * |
|
72 * @param a first operand |
|
73 * @param b second operand |
|
74 * @param result a pointer to a size_t, where the result should |
|
75 * be stored |
|
76 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
77 * otherwise |
|
78 */ |
|
79 #define cx_szmul(a, b, result) cx_szmul_impl(a, b, result) |
|
80 |
|
81 /** |
|
82 * Performs a multiplication of size_t values and checks for overflow. |
|
83 * |
|
84 * This is a custom implementation in case there is no compiler builtin |
|
85 * available. |
|
86 * |
|
87 * @param a first operand |
|
88 * @param b second operand |
|
89 * @param result a pointer to a size_t where the result should be stored |
|
90 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
91 * otherwise |
|
92 */ |
|
93 int cx_szmul_impl(size_t a, size_t b, size_t *result); |
|
94 |
|
95 #endif // cx_szmul |
|
96 |
|
97 |
47 |
98 /** |
48 /** |
99 * Reads data from a stream and writes it to another stream. |
49 * Reads data from a stream and writes it to another stream. |
100 * |
50 * |
101 * @param src the source stream |
51 * @param src the source stream |