From d73162bb6fb986d2edf950f584c36599fa53c45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Sun, 22 Sep 2024 00:48:34 -0700 Subject: [PATCH] pcre2_convert: fix return value again and refactor for clarity 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. --- src/pcre2_convert.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index 5e477a344..571b36c5c 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -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; @@ -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; @@ -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; }