From c1d551e18b0505f4fadf5d7cd6b07de35589bd42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 6 Jul 2020 16:24:33 +0100 Subject: [PATCH] Use static asserts when comparing sizeof() to a constant --- regcomp.c | 2 +- sv.c | 2 +- sv.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/regcomp.c b/regcomp.c index 53e24bb..781399e 100644 --- a/regcomp.c +++ b/regcomp.c @@ -7416,7 +7416,7 @@ S_set_regex_pv(pTHX_ RExC_state_t *pRExC_state, REGEXP *Rx) PERL_ARGS_ASSERT_SET_REGEX_PV; /* make sure PL_bitcount bounds not exceeded */ - assert(sizeof(STD_PAT_MODS) <= 8); + STATIC_ASSERT_STMT(sizeof(STD_PAT_MODS) <= 8); p = sv_grow(MUTABLE_SV(Rx), wraplen + 1); /* +1 for the ending NUL */ SvPOK_on(Rx); diff --git a/sv.c b/sv.c index 9c7f3ba..494b77c 100644 --- a/sv.c +++ b/sv.c @@ -12824,7 +12824,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p (!UVCHR_IS_INVARIANT(uv) && SvUTF8(sv))) && !IN_BYTES) { - assert(sizeof(ebuf) >= UTF8_MAXBYTES + 1); + STATIC_ASSERT_STMT(sizeof(ebuf) >= UTF8_MAXBYTES + 1); eptr = ebuf; elen = uvchr_to_utf8((U8*)eptr, uv) - (U8*)ebuf; is_utf8 = TRUE; diff --git a/sv.h b/sv.h index 2f4a85f..6027f94 100644 --- a/sv.h +++ b/sv.h @@ -2302,7 +2302,7 @@ Evaluates C more than once. Sets C to 0 if C is false. 10:28 <+meta> Nicholas: crash */ # define SvOOK_offset(sv, offset) STMT_START { \ - assert(sizeof(offset) == sizeof(STRLEN)); \ + STATIC_ASSERT_STMT(sizeof(offset) == sizeof(STRLEN)); \ if (SvOOK(sv)) { \ const U8 *_crash = (U8*)SvPVX_const(sv); \ (offset) = *--_crash; \ @@ -2326,7 +2326,7 @@ Evaluates C more than once. Sets C to 0 if C is false. #else /* This is the same code, but avoids using any temporary variables: */ # define SvOOK_offset(sv, offset) STMT_START { \ - assert(sizeof(offset) == sizeof(STRLEN)); \ + STATIC_ASSERT_STMT(sizeof(offset) == sizeof(STRLEN)); \ if (SvOOK(sv)) { \ (offset) = ((U8*)SvPVX_const(sv))[-1]; \ if (!(offset)) { \ -- 1.8.3.1