Commit 5b2f72d297 for perl
commit 5b2f72d297f9cea2f2086caa723aac23bc9553de
Author: Richard Leach <rich+perl@hyphen-dash-hyphen.info>
Date: Thu Oct 15 13:43:57 2026 +0000
Perl_newSV_type - use the largest type to clear sv_u
When a new SV is uprooted in `Perl_newSV_type`, the `sv_u` union is
zeroed once to initialize it for any and all types.
Before this commit, this was done using:
sv->sv_u.svu_rv = NULL;
which is incorrect on platforms where the IV size is larger than the
pointer size. (The NV size, while no larger than the IV size, could
also be larger than the pointer size).
This gave rise to the bug in GH #24964.
With this commit, the larger of `PTRSIZE` or `IVSIZE` determines
whether the union is zeroed using:
sv->sv_u.svu_rv = NULL;
or
sv->sv_u.svu_iv = 0;
diff --git a/sv_inline.h b/sv_inline.h
index 058ebb334f..9bd90e0842 100644
--- a/sv_inline.h
+++ b/sv_inline.h
@@ -395,9 +395,13 @@ Perl_newSV_type(pTHX_ const svtype type)
new_SV(sv);
SvFLAGS(sv) = type;
assert(!SvOK(sv));
- /* Clear the sv_u slot, regardless of what
- * might actually be stored inside it. */
+ /* Clear all bits in the sv_u, regardless of what
+ * might actually get stored inside it. */
+#if PTRSIZE >= IVSIZE
sv->sv_u.svu_rv = NULL;
+#else
+ sv->sv_u.svu_iv = 0;
+#endif
void* new_body;
const struct body_details *type_details;