changeset 25751:4bd60c9c6169

Suppress backtrace when MexErrMsgTxt message ends with newline (bug #54454). * mex.cc (mexErrMsgTxt, mexWarnMsgTxt): If string ends in newline, remove "\n" from string and instead change format to "%s\n" before calling error() or warning().
author Rik <rik@octave.org>
date Tue, 07 Aug 2018 22:12:50 -0700
parents e30a2492eb85
children e4f670d9df5c
files libinterp/corefcn/mex.cc
diffstat 1 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc	Tue Aug 07 08:26:02 2018 -0700
+++ b/libinterp/corefcn/mex.cc	Tue Aug 07 22:12:50 2018 -0700
@@ -3374,8 +3374,18 @@
 void
 mexErrMsgTxt (const char *s)
 {
-  if (s && strlen (s) > 0)
-    error ("%s: %s", mexFunctionName (), s);
+  size_t len;
+
+  if (s && (len = strlen (s)) > 0)
+    {
+      if (s[len - 1] == '\n')
+        {
+          std::string s_tmp (s, len - 1);
+          error ("%s: %s\n", mexFunctionName (), s_tmp.c_str ());
+        }
+      else
+        error ("%s: %s", mexFunctionName (), s);
+    }
   else
     {
       // For compatibility with Matlab, print an empty message.
@@ -3409,7 +3419,24 @@
 void
 mexWarnMsgTxt (const char *s)
 {
-  warning ("%s", s);
+  size_t len;
+
+  if (s && (len = strlen (s)) > 0)
+    {
+      if (s[len - 1] == '\n')
+        {
+          std::string s_tmp (s, len - 1);
+          warning ("%s\n", s_tmp.c_str ());
+        }
+      else
+        warning ("%s", s);
+    }
+  else
+    {
+      // For compatibility with Matlab, print an empty message.
+      // Octave's warning routine requires a non-null input so use a SPACE.
+      warning (" ");
+    }
 }
 
 void