mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +02:00
Refactor regular expression error handling per Coverity report.
Coverity was concerned that regExpError() might return and lead to an invalid reference of "this". This was unlikely since the function should never return but Coverity didn't know that. Also, a difference in error-handling logic at the two sites could cause the issue Coverity reported if they were to get out of sync. Fix by refactoring out the core error function so that it is clear it will never return.
This commit is contained in:
+10
-6
@@ -38,17 +38,21 @@ Handle errors
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
regExpError(int error)
|
||||
{
|
||||
char buffer[4096];
|
||||
regerror(error, NULL, buffer, sizeof(buffer));
|
||||
THROW(FormatError, buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
regExpErrorCheck(int error)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(INT, error);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
if (error != 0 && error != REG_NOMATCH)
|
||||
{
|
||||
char buffer[4096];
|
||||
regerror(error, NULL, buffer, sizeof(buffer));
|
||||
THROW(FormatError, buffer);
|
||||
}
|
||||
regExpError(error);
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
@@ -108,7 +112,7 @@ regExpMatch(RegExp *this, const String *string)
|
||||
int result = regexec(&this->regExp, strPtr(string), 1, &matchPtr, 0);
|
||||
|
||||
// Check for an error
|
||||
regExpError(result);
|
||||
regExpErrorCheck(result);
|
||||
|
||||
// Store match results
|
||||
if (result == 0)
|
||||
|
||||
Reference in New Issue
Block a user