summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embed.fnc1
-rw-r--r--embed.h1
-rw-r--r--handy.h6
-rw-r--r--inline.h9
-rw-r--r--proto.h3
-rw-r--r--sv.c4
-rw-r--r--util.c6
7 files changed, 22 insertions, 8 deletions
diff --git a/embed.fnc b/embed.fnc
index b7a843134c..9fab558b96 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1553,6 +1553,7 @@ Anpa |Malloc_t|safesysmalloc |MEM_SIZE nbytes
Anpa |Malloc_t|safesyscalloc |MEM_SIZE elements|MEM_SIZE size
Anpa |Malloc_t|safesysrealloc|Malloc_t where|MEM_SIZE nbytes
Anp |Free_t |safesysfree |Malloc_t where
+Asrnx |void |croak_memory_wrap
#if defined(PERL_GLOBAL_STRUCT)
Ap |struct perl_vars *|GetVars
Ap |struct perl_vars*|init_global_struct
diff --git a/embed.h b/embed.h
index b21078cbd4..32987bd791 100644
--- a/embed.h
+++ b/embed.h
@@ -76,6 +76,7 @@
#ifndef PERL_IMPLICIT_CONTEXT
#define croak Perl_croak
#endif
+#define croak_memory_wrap S_croak_memory_wrap
#define croak_no_modify() Perl_croak_no_modify(aTHX)
#define croak_sv(a) Perl_croak_sv(aTHX_ a)
#define croak_xs_usage(a,b) Perl_croak_xs_usage(aTHX_ a,b)
diff --git a/handy.h b/handy.h
index 841dd9066c..3b18a0f72c 100644
--- a/handy.h
+++ b/handy.h
@@ -1141,13 +1141,13 @@ PoisonWith(0xEF) for catching access to freed memory.
* overly eager compilers that will bleat about e.g.
* (U16)n > (size_t)~0/sizeof(U16) always being false. */
#ifdef PERL_MALLOC_WRAP
-#define MEM_WRAP_CHECK(n,t) MEM_WRAP_CHECK_1(n,t,PL_memory_wrap)
+#define MEM_WRAP_CHECK(n,t) \
+ (void)(sizeof(t) > 1 && ((MEM_SIZE)(n)+0.0) > MEM_SIZE_MAX/sizeof(t) && (croak_memory_wrap(),0))
#define MEM_WRAP_CHECK_1(n,t,a) \
(void)(sizeof(t) > 1 && ((MEM_SIZE)(n)+0.0) > MEM_SIZE_MAX/sizeof(t) && (Perl_croak_nocontext("%s",(a)),0))
#define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t),
-#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (Perl_croak_nocontext("%s",PL_memory_wrap),0):0),((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1)))
-
+#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (croak_memory_wrap(),0):0),((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1)))
#else
#define MEM_WRAP_CHECK(n,t)
diff --git a/inline.h b/inline.h
index f0d45f6736..69807f1fb7 100644
--- a/inline.h
+++ b/inline.h
@@ -104,3 +104,12 @@ S_sv_or_pv_pos_u2b(pTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
}
#endif
+
+/* ------------------------------- handy.h ------------------------------- */
+
+/* saves machine code for a common noreturn idiom typically used in Newx*() */
+static void
+S_croak_memory_wrap(void)
+{
+ Perl_croak_nocontext("%s",PL_memory_wrap);
+}
diff --git a/proto.h b/proto.h
index d756e1c28c..d069792e28 100644
--- a/proto.h
+++ b/proto.h
@@ -640,6 +640,9 @@ PERL_CALLCONV_NO_RET void Perl_croak(pTHX_ const char* pat, ...)
__attribute__noreturn__
__attribute__format__null_ok__(__printf__,pTHX_1,pTHX_2);
+PERL_STATIC_NO_RET void S_croak_memory_wrap(void)
+ __attribute__noreturn__;
+
PERL_CALLCONV_NO_RET void Perl_croak_no_modify(pTHX)
__attribute__noreturn__;
diff --git a/sv.c b/sv.c
index 1bebb81050..050763e23b 100644
--- a/sv.c
+++ b/sv.c
@@ -11098,13 +11098,13 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
have = esignlen + zeros + elen;
if (have < zeros)
- Perl_croak_nocontext("%s", PL_memory_wrap);
+ croak_memory_wrap();
need = (have > width ? have : width);
gap = need - have;
if (need >= (((STRLEN)~0) - SvCUR(sv) - dotstrlen - 1))
- Perl_croak_nocontext("%s", PL_memory_wrap);
+ croak_memory_wrap();
SvGROW(sv, SvCUR(sv) + need + dotstrlen + 1);
p = SvEND(sv);
if (esignlen && fill == '0') {
diff --git a/util.c b/util.c
index 26330349b5..a8cd6fe70c 100644
--- a/util.c
+++ b/util.c
@@ -307,12 +307,12 @@ Perl_safesyscalloc(MEM_SIZE count, MEM_SIZE size)
#endif
}
else
- Perl_croak_nocontext("%s", PL_memory_wrap);
+ croak_memory_wrap();
#ifdef PERL_TRACK_MEMPOOL
if (sTHX <= MEM_SIZE_MAX - (MEM_SIZE)total_size)
total_size += sTHX;
else
- Perl_croak_nocontext("%s", PL_memory_wrap);
+ croak_memory_wrap();
#endif
#ifdef HAS_64K_LIMIT
if (total_size > 0xffff) {
@@ -3257,7 +3257,7 @@ Perl_repeatcpy(register char *to, register const char *from, I32 len, register I
PERL_ARGS_ASSERT_REPEATCPY;
if (count < 0)
- Perl_croak_nocontext("%s",PL_memory_wrap);
+ croak_memory_wrap();
if (len == 1)
memset(to, *from, count);