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

Allow zero-length substrings to be extracted from the end of a string.

The previous assert was a bit overzealous and did not allow this case.  It's not very common but still occasionally useful.
This commit is contained in:
David Steele 2019-11-16 17:32:49 -05:00
parent 8a3de1e05a
commit 26e1da82e7
2 changed files with 4 additions and 2 deletions

View File

@ -769,7 +769,7 @@ strSub(const String *this, size_t start)
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(start < this->size);
ASSERT(start <= this->size);
FUNCTION_TEST_RETURN(strSubN(this, start, this->size - start));
}
@ -787,7 +787,7 @@ strSubN(const String *this, size_t start, size_t size)
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(start < this->size);
ASSERT(start <= this->size);
ASSERT(start + size <= this->size);
FUNCTION_TEST_RETURN(strNewN(this->buffer + start, size));

View File

@ -195,7 +195,9 @@ testRun(void)
if (testBegin("strSub() and strSubN()"))
{
TEST_RESULT_STR(strPtr(strSub(STRDEF("ABCD"), 2)), "CD", "sub string");
TEST_RESULT_STR_Z(strSub(STRDEF("AB"), 2), "", "zero sub string");
TEST_RESULT_STR(strPtr(strSubN(STRDEF("ABCD"), 1, 2)), "BC", "sub string with length");
TEST_RESULT_STR_Z(strSubN(STRDEF("D"), 1, 0), "", "zero sub string with length");
}
// *****************************************************************************************************************************