# HG changeset patch # User John W. Eaton # Date 1291796704 18000 # Node ID d7fbb08e28cf3a2c1b26fe47888f28a3c5ed2c86 # Parent 71cce7108190e3b7cbfcf7ac6d7bc829e6cebd4f strmatch.m: avoid passing length of 0 to strncmp diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-12-08 John W. Eaton + + * strings/strmatch.m: Avoid passing length of zero to strncmp. + Bug #31774. + 2010-12-07 John W. Eaton * general/repmat.m: Handle special case of replicating scalar diff --git a/scripts/strings/strmatch.m b/scripts/strings/strmatch.m --- 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])