Skip to content

Commit

Permalink
Moved static assert macro away from code-generated file.
Browse files Browse the repository at this point in the history
  • Loading branch information
torben-hansen committed Feb 12, 2022
1 parent 09d6a96 commit 3e31b9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 14 additions & 0 deletions utils/s2n_safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,17 @@ extern int s2n_mul_overflow(uint32_t a, uint32_t b, uint32_t* out);
extern int s2n_align_to(uint32_t initial, uint32_t alignment, uint32_t* out);
extern int s2n_add_overflow(uint32_t a, uint32_t b, uint32_t* out);
extern int s2n_sub_overflow(uint32_t a, uint32_t b, uint32_t* out);

/**
* Define a C99-compliant static assert.
*
* Static_assert() is not defined before C11. So, we can't rely on it when we
* want to be C99 compliant. Instead, use a method that is guaranteed to be C99
* compliant and still give us an equivalent static assert mechanism.
*
* Taken from aws-c-common: https://github.com/awslabs/aws-c-common/blob/main/include/aws/common/macros.h#L19
*/
#define S2N_CONCAT(A, B) A##B
#define S2N_STATIC_ASSERT0(cond, msg) typedef char S2N_CONCAT(static_assertion_, msg)[(!!(cond)) * 2 - 1]
#define S2N_STATIC_ASSERT1(cond, line) S2N_STATIC_ASSERT0(cond, S2N_CONCAT(at_line_, line))
#define S2N_STATIC_ASSERT(cond) S2N_STATIC_ASSERT1(cond, __LINE__)
14 changes: 0 additions & 14 deletions utils/s2n_safety_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,3 @@
* Does not set s2n_errno to S2N_ERR_NULL, so is NOT a direct replacement for PTR_ENSURE_REF.
*/
#define PTR_GUARD_PTR(result) __S2N_ENSURE((result) != NULL, return NULL)

/**
* Define a C99-compliant static assert.
*
* Static_assert() is not defined before C11. So, we can't rely on it when we
* want to be C99 compliant. Instead, use a method that is guaranteed to be C99
* compliant and still give us an equivalent static assert mechanism.
*
* Taken from aws-c-common: https://github.com/awslabs/aws-c-common/blob/main/include/aws/common/macros.h#L19
*/
#define S2N_CONCAT(A, B) A##B
#define S2N_STATIC_ASSERT0(cond, msg) typedef char S2N_CONCAT(static_assertion_, msg)[(!!(cond)) * 2 - 1]
#define S2N_STATIC_ASSERT1(cond, line) S2N_STATIC_ASSERT0(cond, S2N_CONCAT(at_line_, line))
#define S2N_STATIC_ASSERT(cond) S2N_STATIC_ASSERT1(cond, __LINE__)

0 comments on commit 3e31b9f

Please sign in to comment.