changeset 24605:3e17190dfaea stable

Fix incorrect regexprep on ARM platforms (bug #52810). * lo-regexp.cc (regexp::replace): Extend static_cast<size_t> to surround entire length calculations of (end - start + 1).
author Rik <rik@octave.org>
date Mon, 15 Jan 2018 08:08:32 -0800
parents 5609e97cc863
children 4a4a8b2a5bf2
files liboctave/util/lo-regexp.cc
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/lo-regexp.cc	Sun Jan 14 17:17:14 2018 -0800
+++ b/liboctave/util/lo-regexp.cc	Mon Jan 15 08:08:32 2018 -0800
@@ -521,10 +521,11 @@
             for (int j = 0; j < num_tokens; j++)
               {
                 if (tokens[j].num == 0)
-                  pairlen += static_cast<size_t> (end - start) + 1;
+                  pairlen += static_cast<size_t> (end - start + 1);
                 else if (tokens[j].num <= pairs.rows ())
                   pairlen += static_cast<size_t> (pairs(tokens[j].num-1,1)
-                                                  - pairs(tokens[j].num-1,0)) + 1;
+                                                  - pairs(tokens[j].num-1,0)
+                                                  + 1);
               }
             delta += (static_cast<int> (replen + pairlen)
                       - static_cast<int> (end - start + 1));
@@ -543,7 +544,7 @@
             double end = p->end ();
 
             const Matrix pairs (p->token_extents ());
-            rep.append (&buffer[from], static_cast<size_t> (start - 1) - from);
+            rep.append (&buffer[from], static_cast<size_t> (start - 1 - from));
             from = static_cast<size_t> (end);
 
             size_t cur_pos = 0;
@@ -558,14 +559,14 @@
                   {
                     // replace with entire match
                     rep.append (&buffer[static_cast<size_t> (end - 1)],
-                                static_cast<size_t> (end - start) + 1);
+                                static_cast<size_t> (end - start + 1));
                   }
                 else if (k <= pairs.rows ())
                   {
                     // replace with group capture
                     rep.append (&buffer[static_cast<size_t> (pairs(k-1,0)-1)],
                                 static_cast<size_t> (pairs(k-1,1)
-                                                     - pairs(k-1,0)) + 1);
+                                                     - pairs(k-1,0) + 1));
                   }
                 else
                   {
@@ -601,7 +602,7 @@
           {
             OCTAVE_QUIT;
             rep.append (&buffer[from],
-                        static_cast<size_t> (p->start () - 1) - from);
+                        static_cast<size_t> (p->start () - 1 - from));
             from = static_cast<size_t> (p->end ());
             rep.append (repstr);
             p++;