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
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave

View File

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

View File

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

View File

@ -43,24 +43,28 @@
#ifdef __NR_getrandom
#define arc4random_buf(p, l) \
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
#include <time.h>
#define arc4random_buf(p, l) \
do { \
\
srand(time(NULL)); \
u32 i; \
u8 *ptr = (u8 *)p; \
for (i = 0; i < l; i++) \
ptr[i] = rand() % INT_MAX; \
\
ptr[i] = rand() % INT_MAX;
} while (0)
}
while (0)
#endif
#endif