changeset 29128:51bb0e599af4

num2str.m: Fix corner case with literal percent ("%%") at end of format (bug #59527). * num2str.m: Remove literal percent characters from format string ("%%") before counting the number of '%' characters which indicates the number of format arguments present.
author John W. Eaton <jwe@octave.org>
date Mon, 30 Nov 2020 13:42:39 -0800
parents 5b8885af4e2f
children c45cf1fd51b8
files scripts/general/num2str.m
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/num2str.m	Mon Nov 30 13:33:27 2020 -0800
+++ b/scripts/general/num2str.m	Mon Nov 30 13:42:39 2020 -0800
@@ -130,7 +130,8 @@
     nd = ndims (x);
     nc = columns (x) * (nd - 1);    # ND-arrays are expanded in columns
     x  = permute (x, [2, 3:nd, 1]);
-    if (! (sum (fmt == "%") > 1 || any (strcmp (fmt, {"%s", "%c"}))))
+    if (! (sum (strrep (fmt, "%%", "") == "%") > 1
+           || any (strcmp (fmt, {"%s", "%c"}))))
       fmt = [deblank(repmat (fmt, 1, nc)), "\n"];
     endif
     strtmp = sprintf (fmt, x);