1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Allow strIdToLog() to output "null" values.

A valid StringId can never be zero so it more or less serves as a NULL value. In most cases zero will not be valid, but it is better to catch this condition with an assert rather than an error in logging.
This commit is contained in:
David Steele
2024-03-29 12:21:06 +11:00
parent 014e24889c
commit 9f5a97139f
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -383,5 +383,9 @@ strIdToLog(const StringId strId, char *const buffer, const size_t bufferSize)
ASSERT(bufferSize > STRID_MAX);
(void)bufferSize;
// Treat 0 as if it were null since this can never be a valid StringId
if (strId == 0)
return (size_t)snprintf(buffer, bufferSize, NULL_Z);
return strIdToZ(strId, buffer);
}
+4
View File
@@ -700,6 +700,10 @@ testRun(void)
TEST_RESULT_UINT(strIdToLog(TEST_STR5ID2, buffer, sizeof(buffer)), 2, "string id with limited buffer");
TEST_RESULT_UINT(strlen(buffer), 2, " check length");
TEST_RESULT_Z(buffer, "ab", " check buffer");
TEST_RESULT_UINT(strIdToLog(0, buffer, sizeof(buffer)), 4, "null string id");
TEST_RESULT_UINT(strlen(buffer), 4, " check length");
TEST_RESULT_Z(buffer, "null", " check buffer");
}
// *****************************************************************************************************************************