Only process error if not NULL in StoreErrorMessage

pull/1350/head
Marco Slot 2017-04-21 17:01:01 +02:00
parent 7faf4657b7
commit 7f9e80db10
1 changed files with 10 additions and 8 deletions

View File

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