octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #52810] regexprep: incorrect empty tokens on A


From: Colin Macdonald
Subject: [Octave-bug-tracker] [bug #52810] regexprep: incorrect empty tokens on ARM architecture
Date: Sat, 6 Jan 2018 02:40:41 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0

Follow-up Comment #3, bug #52810 (project octave):

I found at least one problem!  And it *is* our fault.


  ...
  if (tokens[j].num == 0)
    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
  ...


Here pairs(...) - pairs(...) can be 45 - 46 = -1.  But then it (I guess) is
cast to something unsigned, giving 0 (on ARM anyway).  Which then has 1 added
to it.

I changed this code to:

  ...
  if (tokens[j].num == 0)
    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)
  ...

And at least pairlen became correct.

But I see several other instances of static_cast<size_t> on double
subtractions which look suspicious.

But maybe the real question is why are double being used as indices into
strings here?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?52810>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]