# HG changeset patch # User Philipp Kutin # Date 1375952317 -7200 # Node ID 334d8edd48bc9023733d43c7a7bf62da80241ced # Parent d87179b38bcf19b5621e70b829dea558fc6c2392 lo-regexp.cc: prevent cast of negative floating point value to size_t. * regexp.cc: simplify two expressions like "static_cast (e - 1) + 1" to "static_cast (e), where 'e' is a nonnegative index value of type double. This prevents a cast of -1.0 to the unsigned integral type "size_t" whenever 'e' is zero. A test case where this occurs (for the second change) is regexprep ('World', '^', 'Hello ', 'emptymatch'). diff --git a/liboctave/util/lo-regexp.cc b/liboctave/util/lo-regexp.cc --- a/liboctave/util/lo-regexp.cc +++ b/liboctave/util/lo-regexp.cc @@ -550,7 +550,7 @@ const Matrix pairs (p->token_extents ()); rep.append (&buffer[from], static_cast (start - 1) - from); - from = static_cast (end - 1) + 1; + from = static_cast (end); size_t cur_pos = 0; @@ -608,7 +608,7 @@ OCTAVE_QUIT; rep.append (&buffer[from], static_cast (p->start () - 1) - from); - from = static_cast (p->end () - 1) + 1; + from = static_cast (p->end ()); rep.append (repstr); p++; }