1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Fixes char-array comparison, bug 289852.

This commit is contained in:
Markus Schorn 2009-09-21 15:06:52 +00:00
parent 38631986c6
commit 7ad14d08db
2 changed files with 13 additions and 2 deletions

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.core.parser.tests;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -39,4 +40,14 @@ public class CharArrayUtilsTest extends TestCase {
Object ivalue4 = map.get("ikey4".toCharArray()); Object ivalue4 = map.get("ikey4".toCharArray());
assertEquals(ivalue4, new Integer(4)); assertEquals(ivalue4, new Integer(4));
} }
public void testEquals_Bug289852() {
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 3, "abc".toCharArray(), false));
assertFalse(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 4, "abcd".toCharArray(), false));
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 2, "ab".toCharArray(), false));
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 3, "ABC".toCharArray(), true));
assertFalse(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 4, "abcd".toCharArray(), true));
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 2, "AB".toCharArray(), true));
}
} }

View file

@ -89,7 +89,7 @@ public class CharArrayUtils {
} }
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) { public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
if (length1 != str2.length || str1.length < length1 ) if (length1 != str2.length || str1.length < length1+start1 )
return false; return false;
if( str1 == str2 && start1 == 0 ) if( str1 == str2 && start1 == 0 )
return true; return true;
@ -104,7 +104,7 @@ public class CharArrayUtils {
if( !ignoreCase ) if( !ignoreCase )
return equals( str1, start1, length1, str2 ); return equals( str1, start1, length1, str2 );
if (length1 != str2.length || str1.length < length1 ) if (length1 != str2.length || str1.length < start1 + length1 )
return false; return false;
for (int i = 0; i < length1; ++i) for (int i = 0; i < length1; ++i)