Skip to content

Commit

Permalink
pcre2_convert: fix return value again and refactor for clarity
Browse files Browse the repository at this point in the history
Since 4f6c43d (Add assertion macros, use new PCRE2_UNREACHABLE
assertion at unreachable points in code (#446), 2024-08-28) and
then again after 04dc664 (Implement PCRE2_UNREACHABLE assertion
for MS Visual C++ (#465), 2024-09-10), this API could return
random values on failure.

Remove assertion, until it could be added back in a way that
wouldn't trigger a crash in non debug builds or result in the
function returning without an API expected value.
  • Loading branch information
carenas committed Sep 22, 2024
1 parent cd4c0e3 commit d73162b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pcre2_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE plength, uint32_t options,
PCRE2_UCHAR **buffptr, PCRE2_SIZE *bufflenptr,
pcre2_convert_context *ccontext)
{
int i, rc;
int rc;
PCRE2_UCHAR dummy_buffer[DUMMY_BUFFER_SIZE];
PCRE2_UCHAR *use_buffer = dummy_buffer;
PCRE2_SIZE use_length = DUMMY_BUFFER_SIZE;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ if (buffptr != NULL && *buffptr != NULL)
/* Call an individual converter, either just once (if a buffer was provided or
just the length is needed), or twice (if a memory allocation is required). */

for (i = 0; i < 2; i++)
for (int i = 0; i < 2; i++)
{
PCRE2_UCHAR *allocated;
BOOL dummyrun = buffptr == NULL || *buffptr == NULL;
Expand Down Expand Up @@ -1158,7 +1158,11 @@ for (i = 0; i < 2; i++)
use_length = *bufflenptr + 1;
}

PCRE2_UNREACHABLE(); /* Control never reaches here */
/* Normally, we should exit this function in the previous loop, but we
can't return an API call without a meaningful value, so if something
went terribly wrong, we then will just report it as an intenal error */

return PCRE2_ERROR_INTERNAL;
}


Expand Down

0 comments on commit d73162b

Please sign in to comment.