From 94f22da279ffb931e1a807288fd77ba1d3e9e2e8 Mon Sep 17 00:00:00 2001 From: Svyatoslav Date: Tue, 18 Apr 2017 15:24:21 +0300 Subject: [PATCH] master_citus_tools.c: PVS-Studio: CWE-476 (NULL Pointer Dereference) --- .../distributed/master/master_citus_tools.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backend/distributed/master/master_citus_tools.c b/src/backend/distributed/master/master_citus_tools.c index 3ccc56aa1..139ede690 100644 --- a/src/backend/distributed/master/master_citus_tools.c +++ b/src/backend/distributed/master/master_citus_tools.c @@ -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); }