1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00

Improve null-handling of varToLog().

This commit is contained in:
David Steele 2019-02-27 18:10:18 +02:00
parent ea2aef1d0c
commit b1957b07f3
3 changed files with 32 additions and 26 deletions

View File

@ -96,7 +96,7 @@
</release-item>
<release-item>
<p>Improve null-handling of <code>strToLog()</code>.</p>
<p>Improve null-handling of <code>strToLog()</code> and <code>varToLog()</code>.</p>
</release-item>
<release-item>

View File

@ -928,40 +928,45 @@ Convert variant to a zero-terminated string for logging
String *
varToLog(const Variant *this)
{
const String *string = NULL;
String *result = NULL;
switch (varType(this))
if (this == NULL)
result = strNew("null");
else
{
case varTypeString:
switch (varType(this))
{
string = strNewFmt("\"%s\"", strPtr(varStrForce(this)));
break;
}
case varTypeString:
{
result = strToLog(varStr(this));
break;
}
case varTypeKeyValue:
{
string = STRING_CONST("KeyValue");
break;
}
case varTypeKeyValue:
{
result = strNew("{KeyValue}");
break;
}
case varTypeVariantList:
{
string = STRING_CONST("VariantList");
break;
}
case varTypeVariantList:
{
result = strNew("{VariantList}");
break;
}
case varTypeBool:
case varTypeDouble:
case varTypeInt:
case varTypeInt64:
case varTypeUInt64:
{
string = varStrForce(this);
break;
case varTypeBool:
case varTypeDouble:
case varTypeInt:
case varTypeInt64:
case varTypeUInt64:
{
result = strNewFmt("{%s}", strPtr(varStrForce(this)));
break;
}
}
}
return strNewFmt("{%s}", strPtr(string));
return result;
}
/***********************************************************************************************************************************

View File

@ -312,6 +312,7 @@ testRun(void)
TEST_RESULT_STR(strPtr(varToLog(varNewBool(false))), "{false}", "format bool");
TEST_RESULT_STR(strPtr(varToLog(varNewKv())), "{KeyValue}", "format KeyValue");
TEST_RESULT_STR(strPtr(varToLog(varNewVarLst(varLstNew()))), "{VariantList}", "format VariantList");
TEST_RESULT_STR(strPtr(varToLog(NULL)), "null", "format null");
}
// *****************************************************************************************************************************