1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Allow NULLs in strEq().

Bring this function more in line with the way varEq() works.  NULL == NULL but NULL != NOT NULL.
This commit is contained in:
David Steele 2019-08-08 10:50:25 -04:00
parent feec674b6f
commit 289b47902b
2 changed files with 10 additions and 5 deletions

View File

@ -465,13 +465,15 @@ strEq(const String *this, const String *compare)
FUNCTION_TEST_PARAM(STRING, compare);
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(compare != NULL);
bool result = false;
if (this->size == compare->size)
result = strcmp(strPtr(this), strPtr(compare)) == 0;
if (this != NULL && compare != NULL)
{
if (this->size == compare->size)
result = strcmp(strPtr(this), strPtr(compare)) == 0;
}
else
result = this == NULL && compare == NULL;
FUNCTION_TEST_RETURN(result);
}

View File

@ -124,6 +124,9 @@ testRun(void)
TEST_RESULT_BOOL(strEq(STRDEF("equalstring"), STRDEF("equalstring")), true, "strings equal");
TEST_RESULT_BOOL(strEq(STRDEF("astring"), STRDEF("anotherstring")), false, "strings not equal");
TEST_RESULT_BOOL(strEq(STRDEF("astring"), STRDEF("bstring")), false, "equal length strings not equal");
TEST_RESULT_BOOL(strEq(NULL, STRDEF("bstring")), false, "null is not equal to bstring");
TEST_RESULT_BOOL(strEq(STRDEF("astring"), NULL), false, "null is not equal to astring");
TEST_RESULT_BOOL(strEq(NULL, NULL), true, "null is equal to null");
TEST_RESULT_INT(strCmp(STRDEF("equalstring"), STRDEF("equalstring")), 0, "strings equal");
TEST_RESULT_INT(strCmp(STRDEF("a"), STRDEF("b")), -1, "a < b");