indenting preprocessor directives breaks compilation and cant be fixed, reverting ... :-(

This commit is contained in:
van Hauser
2020-05-10 12:09:37 +02:00
parent 26f8708fed
commit 30bfd44dfd
43 changed files with 664 additions and 651 deletions

View File

@ -72,7 +72,6 @@ IncludeCategories:
Priority: 3 Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2 IndentWidth: 2
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave JavaScriptQuotes: Leave

View File

@ -47,13 +47,14 @@
#define alloc_printf(_str...) \ #define alloc_printf(_str...) \
({ \ ({ \
\
u8 *_tmp; \ u8 *_tmp; \
s32 _len = snprintf(NULL, 0, _str); \ s32 _len = snprintf(NULL, 0, _str); \
if (_len < 0) FATAL("Whoa, snprintf() fails?!"); \ if (_len < 0) FATAL("Whoa, snprintf() fails?!"); \
_tmp = ck_alloc(_len + 1); \ _tmp = ck_alloc(_len + 1); \
snprintf((char *)_tmp, _len + 1, _str); \ snprintf((char *)_tmp, _len + 1, _str); \
_tmp; \ _tmp; \
\
}) })
/* Macro to enforce allocation limits as a last-resort defense against /* Macro to enforce allocation limits as a last-resort defense against
@ -61,18 +62,18 @@
#define ALLOC_CHECK_SIZE(_s) \ #define ALLOC_CHECK_SIZE(_s) \
do { \ do { \
\
if ((_s) > MAX_ALLOC) ABORT("Bad alloc request: %u bytes", (_s)); \ if ((_s) > MAX_ALLOC) ABORT("Bad alloc request: %u bytes", (_s)); \
\ \
} while (0) } while (0)
/* Macro to check malloc() failures and the like. */ /* Macro to check malloc() failures and the like. */
#define ALLOC_CHECK_RESULT(_r, _s) \ #define ALLOC_CHECK_RESULT(_r, _s) \
do { \ do { \
\
if (!(_r)) ABORT("Out of memory: can't allocate %u bytes", (_s)); \ if (!(_r)) ABORT("Out of memory: can't allocate %u bytes", (_s)); \
\ \
} while (0) } while (0)
/* Allocator increments for ck_realloc_block(). */ /* Allocator increments for ck_realloc_block(). */
@ -213,8 +214,8 @@ static inline u8 *DFL_ck_memdup_str(u8 *mem, u32 size) {
} }
/* In non-debug mode, we just do straightforward aliasing of the above functions /* In non-debug mode, we just do straightforward aliasing of the above
to user-visible names such as ck_alloc(). */ functions to user-visible names such as ck_alloc(). */
#define ck_alloc DFL_ck_alloc #define ck_alloc DFL_ck_alloc
#define ck_alloc_nozero DFL_ck_alloc_nozero #define ck_alloc_nozero DFL_ck_alloc_nozero
@ -234,33 +235,38 @@ static inline u8 *DFL_ck_memdup_str(u8 *mem, u32 size) {
#define alloc_printf(_str...) \ #define alloc_printf(_str...) \
({ \ ({ \
\
\
u8 *_tmp; \ u8 *_tmp; \
s32 _len = snprintf(NULL, 0, _str); \ s32 _len = snprintf(NULL, 0, _str); \
if (_len < 0) FATAL("Whoa, snprintf() fails?!"); \ if (_len < 0) FATAL("Whoa, snprintf() fails?!"); \
_tmp = ck_alloc(_len + 1); \ _tmp = ck_alloc(_len + 1); \
snprintf((char *)_tmp, _len + 1, _str); \ snprintf((char *)_tmp, _len + 1, _str); \
_tmp; \ _tmp;
}) })
/* Macro to enforce allocation limits as a last-resort defense against /* Macro to enforce allocation limits as a last-resort defense against
integer overflows. */ integer overflows. */
#define ALLOC_CHECK_SIZE(_s) \ #define ALLOC_CHECK_SIZE(_s) \
do { \ do { \
if ((_s) > MAX_ALLOC) ABORT("Bad alloc request: %u bytes", (_s)); \
\ \
if ((_s) > MAX_ALLOC) ABORT("Bad alloc request: %u bytes", (_s));
} while (0) }
while (0)
/* Macro to check malloc() failures and the like. */ /* Macro to check malloc() failures and the like. */
#define ALLOC_CHECK_RESULT(_r, _s) \ #define ALLOC_CHECK_RESULT(_r, _s) \
do { \ do { \
if (!(_r)) ABORT("Out of memory: can't allocate %u bytes", (_s)); \
\ \
if (!(_r)) ABORT("Out of memory: can't allocate %u bytes", (_s));
} while (0) }
while (0)
/* Magic tokens used to mark used / freed chunks. */ /* Magic tokens used to mark used / freed chunks. */
@ -285,29 +291,33 @@ static inline u8 *DFL_ck_memdup_str(u8 *mem, u32 size) {
#define CHECK_PTR(_p) \ #define CHECK_PTR(_p) \
do { \ do { \
\
if (_p) { \ if (_p) { \
\
if (ALLOC_C1(_p) ^ ALLOC_MAGIC_C1) { \ if (ALLOC_C1(_p) ^ ALLOC_MAGIC_C1) { \
\
if (ALLOC_C1(_p) == ALLOC_MAGIC_F) \ if (ALLOC_C1(_p) == ALLOC_MAGIC_F) \
ABORT("Use after free."); \ ABORT("Use after free."); \
else \ else \
ABORT("Corrupted head alloc canary."); \ ABORT("Corrupted head alloc canary.");
} \ }
if (ALLOC_C2(_p) ^ ALLOC_MAGIC_C2) \ if (ALLOC_C2(_p) ^ ALLOC_MAGIC_C2) ABORT("Corrupted tail alloc canary.");
ABORT("Corrupted tail alloc canary."); \
} \ }
\ }
} while (0) while (0)
#define CHECK_PTR_EXPR(_p) \ #define CHECK_PTR_EXPR(_p) \
({ \ ({ \
\
\
typeof(_p) _tmp = (_p); \ typeof(_p) _tmp = (_p); \
CHECK_PTR(_tmp); \ CHECK_PTR(_tmp); \
_tmp; \ _tmp;
}) })
@ -355,7 +365,6 @@ static inline void DFL_ck_free(void *mem) {
if (!mem) return; if (!mem) return;
CHECK_PTR(mem); CHECK_PTR(mem);
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
/* Catch pointer issues sooner. */ /* Catch pointer issues sooner. */
@ -539,8 +548,8 @@ static inline u8 *DFL_ck_memdup_str(u8 *mem, u32 size) {
#ifndef DEBUG_BUILD #ifndef DEBUG_BUILD
/* In non-debug mode, we just do straightforward aliasing of the above functions /* In non-debug mode, we just do straightforward aliasing of the above
to user-visible names such as ck_alloc(). */ functions to user-visible names such as ck_alloc(). */
#define ck_alloc DFL_ck_alloc #define ck_alloc DFL_ck_alloc
#define ck_alloc_nozero DFL_ck_alloc_nozero #define ck_alloc_nozero DFL_ck_alloc_nozero
@ -555,8 +564,8 @@ static inline u8 *DFL_ck_memdup_str(u8 *mem, u32 size) {
#else #else
/* In debugging mode, we also track allocations to detect memory leaks, and the /* In debugging mode, we also track allocations to detect memory leaks, and
flow goes through one more layer of indirection. */ the flow goes through one more layer of indirection. */
/* Alloc tracking data structures: */ /* Alloc tracking data structures: */
@ -742,8 +751,7 @@ static inline void TRK_ck_free(void *ptr, const char *file, const char *func,
#define ck_alloc(_p1) TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__) #define ck_alloc(_p1) TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__)
# define ck_alloc_nozero(_p1) \ #define ck_alloc_nozero(_p1) TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__)
TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__)
#define ck_realloc(_p1, _p2) \ #define ck_realloc(_p1, _p2) \
TRK_ck_realloc(_p1, _p2, __FILE__, __FUNCTION__, __LINE__) TRK_ck_realloc(_p1, _p2, __FILE__, __FUNCTION__, __LINE__)

View File

@ -83,18 +83,20 @@ typedef int64_t s64;
#ifndef MIN #ifndef MIN
#define MIN(a, b) \ #define MIN(a, b) \
({ \ ({ \
\
__typeof__(a) _a = (a); \ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \ __typeof__(b) _b = (b); \
_a < _b ? _a : _b; _a < _b ? _a : _b; \
\
}) })
#define MAX(a, b) \ #define MAX(a, b) \
({ \ ({ \
\
__typeof__(a) _a = (a); \ __typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \ __typeof__(b) _b = (b); \
_a > _b ? _a : _b; _a > _b ? _a : _b; \
\
}) })
#endif /* !MIN */ #endif /* !MIN */

View File

@ -43,24 +43,28 @@
#ifdef __NR_getrandom #ifdef __NR_getrandom
#define arc4random_buf(p, l) \ #define arc4random_buf(p, l) \
do { \ do { \
ssize_t rd = syscall(__NR_getrandom, p, l, 0); \
if (rd != l) DEBUGF("getrandom failed"); \
\ \
ssize_t rd = syscall(__NR_getrandom, p, l, 0); \
if (rd != l) DEBUGF("getrandom failed");
} while (0) }
while (0)
#else #else
#include <time.h> #include <time.h>
#define arc4random_buf(p, l) \ #define arc4random_buf(p, l) \
do { \ do { \
\
srand(time(NULL)); \ srand(time(NULL)); \
u32 i; \ u32 i; \
u8 *ptr = (u8 *)p; \ u8 *ptr = (u8 *)p; \
for (i = 0; i < l; i++) \ for (i = 0; i < l; i++) \
ptr[i] = rand() % INT_MAX; \ ptr[i] = rand() % INT_MAX;
\
} while (0) }
while (0)
#endif #endif
#endif #endif