# HG changeset patch # User Rik # Date 1516032512 28800 # Node ID 845ec6f4fb968dbc9f8aae7547a05bcd64783c06 # Parent e578e68ba1e03c1bea42108c82c63f61f48d0586 Fix incorrect regexprep on ARM platforms (bug #52810). * lo-regexp.cc (regexp::replace): Extend static_cast to surround entire length calculations of (end - start + 1). diff -r e578e68ba1e0 -r 845ec6f4fb96 liboctave/util/lo-regexp.cc --- 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 (end - start) + 1; + pairlen += static_cast (end - start + 1); else if (tokens[j].num <= pairs.rows ()) pairlen += static_cast (pairs(tokens[j].num-1,1) - - pairs(tokens[j].num-1,0)) + 1; + - pairs(tokens[j].num-1,0) + + 1); } delta += (static_cast (replen + pairlen) - static_cast (end - start + 1)); @@ -543,7 +545,7 @@ double end = p->end (); const Matrix pairs (p->token_extents ()); - rep.append (&buffer[from], static_cast (start - 1) - from); + rep.append (&buffer[from], static_cast (start - 1 - from)); from = static_cast (end); size_t cur_pos = 0; @@ -558,14 +560,14 @@ { // replace with entire match rep.append (&buffer[static_cast (end - 1)], - static_cast (end - start) + 1); + static_cast (end - start + 1)); } else if (k <= pairs.rows ()) { // replace with group capture rep.append (&buffer[static_cast (pairs(k-1,0)-1)], static_cast (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 (p->start () - 1) - from); + static_cast (p->start () - 1 - from)); from = static_cast (p->end ()); rep.append (repstr); p++;