From: Paul Eggert Date: Sun, 2 Oct 2022 20:37:39 +0000 (-0700) Subject: Prefer static_assert to verify in seccomp-filter X-Git-Tag: emacs-29.0.90~1856^2~69 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5598886adc9f7bc83ba9775151f839d4691128e4;p=emacs.git Prefer static_assert to verify in seccomp-filter Prefer static_assert in just one file for now; the idea is to do it elsewhere eventually. static_assert is standard (starting with C23) whereas verify is not, and static_assert can be used even in pre-C23 files due to Gnulib’s support for it. * lib-src/seccomp-filter.c: Do not include verify.h. Prefer static_assert to verify. --- diff --git a/lib-src/seccomp-filter.c b/lib-src/seccomp-filter.c index 4bd2816dfc5..061af9dc072 100644 --- a/lib-src/seccomp-filter.c +++ b/lib-src/seccomp-filter.c @@ -59,7 +59,6 @@ variants of those files that can be used to sandbox Emacs before #include #include -#include #ifndef ARCH_CET_STATUS #define ARCH_CET_STATUS 0x3001 @@ -167,12 +166,12 @@ main (int argc, char **argv) set_attribute (SCMP_FLTATR_CTL_NNP, 1); set_attribute (SCMP_FLTATR_CTL_TSYNC, 1); - verify (CHAR_BIT == 8); - verify (sizeof (int) == 4 && INT_MIN == INT32_MIN - && INT_MAX == INT32_MAX); - verify (sizeof (long) == 8 && LONG_MIN == INT64_MIN - && LONG_MAX == INT64_MAX); - verify (sizeof (void *) == 8); + static_assert (CHAR_BIT == 8); + static_assert (sizeof (int) == 4 && INT_MIN == INT32_MIN + && INT_MAX == INT32_MAX); + static_assert (sizeof (long) == 8 && LONG_MIN == INT64_MIN + && LONG_MAX == INT64_MAX); + static_assert (sizeof (void *) == 8); assert ((uintptr_t) NULL == 0); /* Allow a clean exit. */ @@ -182,8 +181,8 @@ main (int argc, char **argv) /* Allow `mmap' and friends. This is necessary for dynamic loading, reading the portable dump file, and thread creation. We don't allow pages to be both writable and executable. */ - verify (MAP_PRIVATE != 0); - verify (MAP_SHARED != 0); + static_assert (MAP_PRIVATE != 0); + static_assert (MAP_SHARED != 0); RULE (SCMP_ACT_ALLOW, SCMP_SYS (mmap), SCMP_A2_32 (SCMP_CMP_MASKED_EQ, ~(PROT_NONE | PROT_READ | PROT_WRITE)), @@ -255,9 +254,9 @@ main (int argc, char **argv) /* Allow opening files, assuming they are only opened for reading. */ - verify (O_WRONLY != 0); - verify (O_RDWR != 0); - verify (O_CREAT != 0); + static_assert (O_WRONLY != 0); + static_assert (O_RDWR != 0); + static_assert (O_CREAT != 0); RULE (SCMP_ACT_ALLOW, SCMP_SYS (open), SCMP_A1_32 (SCMP_CMP_MASKED_EQ, ~(O_RDONLY | O_BINARY | O_CLOEXEC | O_PATH