changeset 26350:86b7dec68d09 stable

error.cc: Fix static analyzer detected issues (bug #55347). * error.cc (handle_message): Check arg.isempty () first to avoid having to check C string for validity. Add comments about why temporary variable is required during conversion of std::string to *char.
author Rik <rik@octave.org>
date Tue, 01 Jan 2019 20:25:54 -0800
parents 6ec8b2eab987
children f6473e416fa2
files libinterp/corefcn/error.cc
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Tue Jan 01 19:55:29 2019 -0800
+++ b/libinterp/corefcn/error.cc	Tue Jan 01 20:25:54 2019 -0800
@@ -972,7 +972,7 @@
 {
   std::string retval;
 
-  std::string tstr;
+  std::string tmpstr;
 
   if (args.length () > 0)
     {
@@ -988,20 +988,18 @@
 
       if (arg.is_defined ())
         {
-          if (arg.is_string ())
+          if (arg.isempty ())
+            return retval;
+          else if (arg.is_string ())
             {
-              tstr = arg.string_value ();
-              msg = tstr.c_str ();
-
-              if (! msg)
-                return retval;
+              tmpstr = arg.string_value ();  // 2-stage assignment required
+              msg = tmpstr.c_str ();         // in order to generate pointer  
+                                             // to valid memory.
             }
-          else if (arg.isempty ())
-            return retval;
         }
     }
 
-// Ugh.
+  // Ugh.
 
   size_t len = strlen (msg);