master_citus_tools.c: PVS-Studio: CWE-476 (NULL Pointer Dereference)

pull/1334/head
Svyatoslav 2017-04-18 15:24:21 +03:00
parent ecddb78815
commit 94f22da279
1 changed files with 10 additions and 7 deletions

View File

@ -435,19 +435,22 @@ static void
StoreErrorMessage(PGconn *connection, StringInfo queryResultString)
{
char *errorMessage = PQerrorMessage(connection);
char *firstNewlineIndex = strchr(errorMessage, '\n');
/* trim the error message at the line break */
if (firstNewlineIndex != NULL)
{
*firstNewlineIndex = '\0';
}
/* put a default error message if no error message is reported */
if (errorMessage == NULL)
{
errorMessage = "An error occurred while running the query";
}
else
{
char *firstNewlineIndex = strchr(errorMessage, '\n');
/* trim the error message at the line break */
if (firstNewlineIndex != NULL)
{
*firstNewlineIndex = '\0';
}
}
appendStringInfo(queryResultString, "%s", errorMessage);
}