changeset 24603:845ec6f4fb96

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 e578e68ba1e0
children 6b3c78f84d3b
files liboctave/util/lo-regexp.cc
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/lo-regexp.cc	Mon Jan 15 08:07:38 2018 -0800
+++ b/liboctave/util/lo-regexp.cc	Mon Jan 15 08:08:32 2018 -0800
@@ -230,7 +230,8 @@
          | (options.lineanchors () ? PCRE_MULTILINE : 0)
          | (options.freespacing () ? PCRE_EXTENDED : 0));
 
-    data = pcre_compile (buf_str.c_str (), pcre_options, &err, &erroffset, nullptr);
+    data = pcre_compile (buf_str.c_str (), pcre_options,
+                         &err, &erroffset, nullptr);
 
     if (! data)
       (*current_liboctave_error_handler)
@@ -521,10 +522,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 +545,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 +560,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
                   {
@@ -603,7 +605,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++;