From fc8abf23fa85601cc5cb9aa197b5c77b69d5857b Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 18 Mar 2025 14:16:40 +0000 Subject: [PATCH] Fix some nasty incompatible pointer casts --- src/pcre2_compile.c | 7 +++++-- src/pcre2_dfa_match.c | 3 ++- src/pcre2_match.c | 3 ++- src/pcre2_substitute.c | 5 +++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index f0147d5f3..34c4ee770 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -10179,8 +10179,9 @@ pcre2_real_code *re = NULL; /* What we will return */ compile_block cb; /* "Static" compile-time data */ const uint8_t *tables; /* Char tables base pointer */ +PCRE2_UCHAR null_str[1] = { 0xcd }; /* Dummy for handling null inputs */ PCRE2_UCHAR *code; /* Current pointer in compiled code */ -PCRE2_UCHAR * codestart; /* Start of compiled code */ +PCRE2_UCHAR *codestart; /* Start of compiled code */ PCRE2_SPTR ptr; /* Current pointer in pattern */ uint32_t *pptr; /* Current pointer in parsed pattern */ @@ -10235,7 +10236,9 @@ if (errorptr == NULL || erroroffset == NULL) return NULL; if (pattern == NULL) { - if (patlen == 0) pattern = (PCRE2_SPTR)""; else + if (patlen == 0) + pattern = null_str; + else { *errorptr = ERR16; return NULL; diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index 8728de5c6..0b35d8cde 100644 --- a/src/pcre2_dfa_match.c +++ b/src/pcre2_dfa_match.c @@ -3346,6 +3346,7 @@ int was_zero_terminated = 0; const pcre2_real_code *re = (const pcre2_real_code *)code; +PCRE2_UCHAR null_str[1] = { 0xcd }; PCRE2_SPTR start_match; PCRE2_SPTR end_subject; PCRE2_SPTR bumpalong_limit; @@ -3387,7 +3388,7 @@ rws->free = RWS_BASE_SIZE - RWS_ANCHOR_SIZE; /* Recognize NULL, length 0 as an empty string. */ -if (subject == NULL && length == 0) subject = (PCRE2_SPTR)""; +if (subject == NULL && length == 0) subject = null_str; /* Plausibility checks */ diff --git a/src/pcre2_match.c b/src/pcre2_match.c index f246fc4ca..53b734fce 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -6939,6 +6939,7 @@ PCRE2_UCHAR first_cu2 = 0; PCRE2_UCHAR req_cu = 0; PCRE2_UCHAR req_cu2 = 0; +PCRE2_UCHAR null_str[1] = { 0xcd }; PCRE2_SPTR bumpalong_limit; PCRE2_SPTR end_subject; PCRE2_SPTR true_end_subject; @@ -6977,7 +6978,7 @@ match_block *mb = &actual_match_block; /* Recognize NULL, length 0 as an empty string. */ -if (subject == NULL && length == 0) subject = (PCRE2_SPTR)""; +if (subject == NULL && length == 0) subject = null_str; /* Plausibility checks */ diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c index 3a95ab4d2..a5ef2a347 100644 --- a/src/pcre2_substitute.c +++ b/src/pcre2_substitute.c @@ -749,6 +749,7 @@ BOOL use_existing_match; BOOL replacement_only; BOOL utf = (code->overall_options & PCRE2_UTF) != 0; PCRE2_UCHAR temp[6]; +PCRE2_UCHAR null_str[1] = { 0xcd }; PCRE2_SPTR ptr; PCRE2_SPTR repend = NULL; PCRE2_SIZE extra_needed = 0; @@ -786,7 +787,7 @@ zero length is interpreted as an empty string. */ if (replacement == NULL) { if (rlength != 0) return PCRE2_ERROR_NULL; - replacement = (PCRE2_SPTR)""; + replacement = null_str; } if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement); @@ -859,7 +860,7 @@ scb.ovector = ovector; if (subject == NULL) { if (length != 0) return PCRE2_ERROR_NULL; - subject = (PCRE2_SPTR)""; + subject = null_str; } /* Find length of zero-terminated subject */