comparison liboctave/util/lo-regexp.cc @ 17211:334d8edd48bc

lo-regexp.cc: prevent cast of negative floating point value to size_t. * regexp.cc: simplify two expressions like "static_cast<size_t> (e - 1) + 1" to "static_cast<size_t> (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').
author Philipp Kutin <philipp.kutin@gmail.com>
date Thu, 08 Aug 2013 10:58:37 +0200
parents 99122191d3dd
children
comparison
equal deleted inserted replaced
17210:d87179b38bcf 17211:334d8edd48bc
548 double start = p->start (); 548 double start = p->start ();
549 double end = p->end (); 549 double end = p->end ();
550 550
551 const Matrix pairs (p->token_extents ()); 551 const Matrix pairs (p->token_extents ());
552 rep.append (&buffer[from], static_cast<size_t> (start - 1) - from); 552 rep.append (&buffer[from], static_cast<size_t> (start - 1) - from);
553 from = static_cast<size_t> (end - 1) + 1; 553 from = static_cast<size_t> (end);
554 554
555 size_t cur_pos = 0; 555 size_t cur_pos = 0;
556 556
557 for (int j = 0; j < num_tokens; j++) 557 for (int j = 0; j < num_tokens; j++)
558 { 558 {
606 for (size_t i = 0; i < num_matches; i++) 606 for (size_t i = 0; i < num_matches; i++)
607 { 607 {
608 OCTAVE_QUIT; 608 OCTAVE_QUIT;
609 rep.append (&buffer[from], 609 rep.append (&buffer[from],
610 static_cast<size_t> (p->start () - 1) - from); 610 static_cast<size_t> (p->start () - 1) - from);
611 from = static_cast<size_t> (p->end () - 1) + 1; 611 from = static_cast<size_t> (p->end ());
612 rep.append (repstr); 612 rep.append (repstr);
613 p++; 613 p++;
614 } 614 }
615 rep.append (&buffer[from], buffer.size () - from); 615 rep.append (&buffer[from], buffer.size () - from);
616 } 616 }