Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvi fixes #2254

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions contrib/nvi/common/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
*
* See the LICENSE file for redistribution information.
*/
/*
* CHERI CHANGES START
* {
* "updated": 20221129,
* "target_type": "prog",
* "changes": [
* "pointer_alignment"
* ]
* }
* CHERI CHANGES END
*/

#include "config.h"

Expand Down Expand Up @@ -717,29 +706,18 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp,
recno_t lno, u_char *p, size_t len)
{
#ifdef USE_WIDECHAR
typedef unsigned long nword;

static size_t blen;
static nword *bp;
nword *lp = (nword *)__builtin_align_down(p, sizeof(nword));
if (lp != (nword *)p) {
int offl = ((caddr_t)p - (caddr_t)lp) << 3;
int offr = (sizeof(nword) << 3) - offl;
size_t i, cnt = (len + sizeof(nword) / 2) / sizeof(nword);
static u_char *bp;

if (!is_aligned(p, sizeof(unsigned long))) {
if (len > blen) {
blen = p2roundup(MAX(len, 512));
REALLOC(sp, bp, nword *, blen);
REALLOC(sp, bp, u_char *, blen);
if (bp == NULL)
return (1);
}
for (i = 0; i < cnt; ++i)
#if BYTE_ORDER == BIG_ENDIAN
bp[i] = (lp[i] << offl) ^ (lp[i+1] >> offr);
#else
bp[i] = (lp[i] >> offl) ^ (lp[i+1] << offr);
#endif
p = (u_char *)bp;
memmove(bp, p, len);
p = bp;
}
#endif
return db_func(sp, lno, (CHAR_T *)p, len / sizeof(CHAR_T));
Expand Down
12 changes: 12 additions & 0 deletions contrib/nvi/common/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@
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

Check warning on line 220 in contrib/nvi/common/mem.h

View workflow job for this annotation

GitHub Actions / Style Checker

line over 80 characters
*/
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)

Check warning on line 229 in contrib/nvi/common/mem.h

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
Loading