diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/common.h | 1 | ||||
-rw-r--r-- | common/log.c | 23 | ||||
-rw-r--r-- | common/mem.h | 12 | ||||
-rw-r--r-- | common/options.c | 4 |
4 files changed, 21 insertions, 19 deletions
diff --git a/common/common.h b/common/common.h index 45f22fb49d1b..fd97a4655cf5 100644 --- a/common/common.h +++ b/common/common.h @@ -17,6 +17,7 @@ #include <db.h> #endif #include <regex.h> /* May refer to the bundled regex. */ +#include <stdint.h> /* * Forward structure declarations. Not pretty, but the include files diff --git a/common/log.c b/common/log.c index 96b246efad02..7aad94d7e74a 100644 --- a/common/log.c +++ b/common/log.c @@ -18,7 +18,6 @@ #include <fcntl.h> #include <libgen.h> #include <limits.h> -#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -706,30 +705,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 *)((uintptr_t)p / sizeof(nword) * sizeof(nword)); - - if (lp != (nword *)p) { - int offl = ((uintptr_t)p - (uintptr_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)); diff --git a/common/mem.h b/common/mem.h index d24ec0b50b09..0c83b70dec2f 100644 --- a/common/mem.h +++ b/common/mem.h @@ -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) diff --git a/common/options.c b/common/options.c index c3d1f7343f9a..87d5c5a88521 100644 --- a/common/options.c +++ b/common/options.c @@ -181,6 +181,8 @@ OPTLIST const optlist[] = { {L("shellmeta"), NULL, OPT_STR, 0}, /* O_SHIFTWIDTH 4BSD */ {L("shiftwidth"), NULL, OPT_NUM, OPT_NOZERO}, +/* O_SHOWFILENAME */ + {L("showfilename"), NULL, OPT_0BOOL, 0}, /* O_SHOWMATCH 4BSD */ {L("showmatch"), NULL, OPT_0BOOL, 0}, /* O_SHOWMODE 4.4BSD */ @@ -317,7 +319,7 @@ opts_init(SCR *sp, int *oargs) /* Set numeric and string default values. */ #define OI(indx, str) do { \ a.len = STRLEN(str); \ - if ((CHAR_T*)str != b2) /* GCC puts strings in text-space. */ \ + if (STRCMP((CHAR_T*)str, b2) != 0) \ (void)MEMCPY(b2, str, a.len+1); \ if (opts_set(sp, argv, NULL)) { \ optindx = indx; \ |