From e093a98588b604bf9693213772ab959c303d0ac4 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Mon, 18 May 2020 08:23:38 -0400
Subject: [PATCH] Glob: Append warning message only if destination is non-null

Fix the change from commit f33ef4e3e (Glob: issue warnings on Directory
errors, 2020-05-12) to not append to nullptr messages.
---
 Glob.cxx | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Glob.cxx b/Glob.cxx
index 364305f5..c52aafc4 100644
--- a/Glob.cxx
+++ b/Glob.cxx
@@ -184,10 +184,12 @@ bool Glob::RecurseDirectory(std::string::size_type start,
   kwsys::Directory d;
   std::string errorMessage;
   if (!d.Load(dir, &errorMessage)) {
-    if (!errorMessage.empty()) {
-      messages->push_back(Message(Glob::warning,
-                                  "Error listing directory '" + dir +
-                                    "'! Reason: '" + errorMessage + "'"));
+    if (messages) {
+      if (!errorMessage.empty()) {
+        messages->push_back(Message(Glob::warning,
+                                    "Error listing directory '" + dir +
+                                      "'! Reason: '" + errorMessage + "'"));
+      }
     }
     return true;
   }
-- 
GitLab