From 839c1a190fb7e7e3b89062c66b885456c1dfb85b Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:16:00 +0200 Subject: [PATCH] [Fix #22254] Put real storage behind `PM_STRING_EMPTY` Some places memcpy the source, and NULL there is undefined behaviour. Fixes https://bugs.ruby-lang.org/issues/22254 --- include/prism/internal/stringy.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/prism/internal/stringy.h b/include/prism/internal/stringy.h index 1aaa23ea75..f6716c8790 100644 --- a/include/prism/internal/stringy.h +++ b/include/prism/internal/stringy.h @@ -3,11 +3,16 @@ #include "prism/stringy.h" +/* + * Backing storage for an empty string. + */ +static const uint8_t empty_source[] = ""; + /* * Defines an empty string. This is useful for initializing a string that will * be filled in later. */ -#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 }) +#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = empty_source, .length = 0 }) /* * Initialize a shared string that is based on initial input.