Skip to content

Commit d0b36ce

Browse files
authored
[Fix #22254] Put real storage behind PM_STRING_EMPTY (#4228)
Some places memcpy the source, and NULL there is undefined behaviour. Fixes https://bugs.ruby-lang.org/issues/22254
1 parent 589d108 commit d0b36ce

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎include/prism/internal/stringy.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
#include "prism/stringy.h"
55

6+
/*
7+
* Backing storage for an empty string.
8+
*/
9+
static const uint8_t empty_source[] = "";
10+
611
/*
712
* Defines an empty string. This is useful for initializing a string that will
813
* be filled in later.
914
*/
10-
#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 })
15+
#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = empty_source, .length = 0 })
1116

1217
/*
1318
* Initialize a shared string that is based on initial input.

0 commit comments

Comments
 (0)