Mercurial > octave
changeset 21498:9cb37fede0b6
textscan: Compare pointers or sizes rather than their arithmetic difference
* textscan.cc (delimited_stream::refresh_buf) Compare pointers rather than
comparing their difference to zero. (textscan::read_until,
textscan::skip_whitespace): Compare string lengths rather than comparing
their difference to zero.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 18 Mar 2016 23:35:10 -0700 |
parents | 2d71bb0011a0 |
children | 365c3e0add98 |
files | libinterp/corefcn/textscan.cc |
diffstat | 1 files changed, 14 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/textscan.cc Fri Mar 18 23:08:18 2016 -0700 +++ b/libinterp/corefcn/textscan.cc Fri Mar 18 23:35:10 2016 -0700 @@ -285,13 +285,11 @@ return std::istream::traits_type::eof (); int retval; - int old_remaining = eob - idx; - - if (old_remaining < 0) - { - idx = eob; - old_remaining = 0; - } + + if (eob < idx) + idx = eob; + + size_t old_remaining = eob - idx; octave_quit (); // allow ctrl-C @@ -333,7 +331,7 @@ break; } - if (last - buf < 0) + if (last < buf) delimited = false; retval = 0; @@ -1859,9 +1857,9 @@ for (int i = 0; i < delimiters.numel (); i++) { std::string delim = delimiters(i).string_value (); - int start = retval.length () - delim.length (); - if (start < 0) - start = 0; + size_t start = (retval.length () > delim.length () + ? retval.length () - delim.length () + : 0); std::string may_match = retval.substr (start); if (may_match == delim) { @@ -2577,10 +2575,11 @@ is.get_undelim (); // (read last itself) may_match = may_match + dummy + last; - int start = may_match.length () - end_c.length (); - if (start < 0) - start = 0; - may_match = may_match.substr (start); + if (may_match.length () > end_c.length ()) + { + size_t start = may_match.length () - end_c.length (); + may_match = may_match.substr (start); + } } while (may_match != end_c && is && ! is.eof ()); }