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,6 +435,14 @@ static void
StoreErrorMessage(PGconn *connection, StringInfo queryResultString) StoreErrorMessage(PGconn *connection, StringInfo queryResultString)
{ {
char *errorMessage = PQerrorMessage(connection); char *errorMessage = PQerrorMessage(connection);
/* 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'); char *firstNewlineIndex = strchr(errorMessage, '\n');
/* trim the error message at the line break */ /* trim the error message at the line break */
@ -442,11 +450,6 @@ StoreErrorMessage(PGconn *connection, StringInfo queryResultString)
{ {
*firstNewlineIndex = '\0'; *firstNewlineIndex = '\0';
} }
/* put a default error message if no error message is reported */
if (errorMessage == NULL)
{
errorMessage = "An error occurred while running the query";
} }
appendStringInfo(queryResultString, "%s", errorMessage); appendStringInfo(queryResultString, "%s", errorMessage);