Mercurial > hg > octave-terminal
changeset 10585:9f55d3ce490a
avoid crash when setting graphics property from cellstr object
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Apr 2010 21:54:41 -0400 |
parents | 6a81e809a392 |
children | ec3cec8277df |
files | src/ChangeLog src/graphics.h.in |
diffstat | 2 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2010-04-27 John W. Eaton <jwe@octave.org> + + * graphics.h.in (string_array_property::string_array_property): + Index string_vector with [], not (). + (string_array_property::string_value): Likewise. + (string_array_property::do_set): Likewise. + Avoid indexing past last element of string_vector object. + Fixes bug #29695. + 2010-04-27 Jaroslav Hajek <highegg@gmail.com> * ov-cs-list.cc (octave_cs_list::subsref): New methods. Just gripe.
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -552,7 +552,7 @@ string_vector strings (c.numel ()); for (octave_idx_type i = 0; i < c.numel (); i++) - strings (i) = c(i).string_value (); + strings[i] = c(i).string_value (); str = strings; } @@ -575,16 +575,16 @@ std::string string_value (void) const { - std::string _str; + std::string s; for (octave_idx_type i = 0; i < str.length (); i++) { - _str += str(i); - if (i != str.length() - 1) - _str += separator; + s += str[i]; + if (i != str.length () - 1) + s += separator; } - return _str; + return s; } Cell cell_value (void) const {return Cell (str);} @@ -625,7 +625,7 @@ if (str.numel () == strings.numel ()) { for (octave_idx_type i = 0; i < str.numel (); i++) - if (strings (i) != str(i)) + if (strings[i] != str[i]) { replace = true; break; @@ -645,13 +645,22 @@ bool replace = false; Cell new_cell = val.cell_value (); - string_vector strings (new_cell.numel ()); - - for (octave_idx_type i = 0; i < new_cell.numel (); i++) + string_vector strings = new_cell.cellstr_value (); + + octave_idx_type nel = strings.length (); + + if (nel != str.length ()) + replace = true; + else { - strings (i) = new_cell(i).string_value (); - if (strings (i) != str (i)) - replace = true; + for (octave_idx_type i = 0; i < nel; i++) + { + if (strings[i] != str[i]) + { + replace = true; + break; + } + } } if (replace)