Mercurial > hg > octave-nkf
changeset 11323:d7fbb08e28cf
strmatch.m: avoid passing length of 0 to strncmp
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Dec 2010 03:25:04 -0500 |
parents | 71cce7108190 |
children | e773d57de572 |
files | scripts/ChangeLog scripts/strings/strmatch.m |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-12-08 John W. Eaton <jwe@octave.org> + + * strings/strmatch.m: Avoid passing length of zero to strncmp. + Bug #31774. + 2010-12-07 John W. Eaton <jwe@octave.org> * general/repmat.m: Handle special case of replicating scalar
--- a/scripts/strings/strmatch.m +++ b/scripts/strings/strmatch.m @@ -64,7 +64,11 @@ exact = nargin == 3 && ischar (exact) && strcmp (exact, "exact"); if (iscell (A)) - idx = find (strncmp (s, A, len)); + if (len > 0) + idx = find (strncmp (s, A, len)); + else + idx = find (strcmp (s, A)); + endif if (exact) ## We can't just use strcmp, because we need to ignore whitespace. B = cellfun (@strtrimr, A(idx), "uniformoutput", false); @@ -107,4 +111,4 @@ %! [1; 2]); %!assert (strmatch ("apple pie", "apple"), []); %!assert (strmatch ("a b", {"a b", "a c", "c d"})); - +%!assert (strmatch ("", {"", "foo", "bar", ""}), [1, 4])