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:
parent
8a3de1e05a
commit
26e1da82e7
@ -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));
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user