mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-18 05:53:36 +01:00
nvi: Replace Clang-only __builtin_is_aligned with C code (#124)
We should use alignof in the future.
Obtained from: 25c4d7db4e
This commit is contained in:
parent
56ef9c872b
commit
06a98fefd3
@ -709,7 +709,7 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp,
|
||||
static size_t blen;
|
||||
static u_char *bp;
|
||||
|
||||
if (!__builtin_is_aligned(p, sizeof(unsigned long))) {
|
||||
if (!is_aligned(p, sizeof(unsigned long))) {
|
||||
if (len > blen) {
|
||||
blen = p2roundup(MAX(len, 512));
|
||||
REALLOC(sp, bp, u_char *, blen);
|
||||
|
@ -212,6 +212,18 @@ p2roundup(size_t n)
|
||||
return (n);
|
||||
}
|
||||
|
||||
/*
|
||||
* is_aligned --
|
||||
* Determine whether the program can safely read an object with an
|
||||
* alignment requirement from ptr.
|
||||
*
|
||||
* See also: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins
|
||||
*/
|
||||
static __inline int
|
||||
is_aligned(void *ptr, size_t alignment) {
|
||||
return ((uintptr_t)ptr % alignment) == 0;
|
||||
}
|
||||
|
||||
/* Additional TAILQ helper. */
|
||||
#define TAILQ_ENTRY_ISVALID(elm, field) \
|
||||
((elm)->field.tqe_prev != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user