Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] WordEntry out of bounds exception patch

Folks,

  This patch addresses a problem which occurs when we are updating the
index mappings for large projects.  It may only address the symptom,
since I'm not totally up to speed on all the indexer logic yet, but 
it is a valid case to consider.  When an index word reference is set 
to:

reference[1 3 4] but there is a new mapping[1 2 3 4 5] then we iterate 
the old references through the new mapping giving a new reference of
newReference[mapping[1], mapping[3], mapping[4]] == [2 4 5].  If there
are any invalid mappings (-1 or 0) then these are ignored in the new
reference.

There is a problem however when the mapping has "shrunk" so that the
reference is an index which is too large for the mapping ie
reference[1 4696] and mapping[1 2] (ie the mapping is < 4696).  This
should translate to (I believe) a new reference of [2] based on 
the current logic which ignores -1 mappings.

All that to say, this is a range checking patch.  Without this patch
a large source base may have to continuously re-index itself.  With
this patch the index is considered valid and it only has to do a full
index once.

Changelog

- Consider references outside of the mapping range the same as no longer
  valid mappings (ie -1 entries) and avoid array range exceptions.

--- PATCH START ---
Index: index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java
===================================================================
RCS 
file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/in
dex/impl/WordEntry.java,v
retrieving revision 1.3
diff -u -r1.3 WordEntry.java
--- index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java	12 
Aug 2003 20:20:04 -0000	1.3
+++ index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java	2 
Feb 2004 10:17:45 -0000
@@ -128,8 +128,12 @@
 	 */
 	public void mapRefs(int[] mappings) {
 		int position= 0;
+
 		for (int i= 0; i < fNumRefs; i++) {
-			int map= mappings[fRefs[i]];
+			//Take care that the reference is actually within 
the bounds of the mapping
+			int map= -1;
+			if(fRefs[i] >= 0 && fRefs[i] < mappings.length) 
+				map= mappings[fRefs[i]];
 			if (map != -1 && map != 0)
 				fRefs[position++]= map;
 		}
--- PATCH END ---
Index: index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java,v
retrieving revision 1.3
diff -u -r1.3 WordEntry.java
--- index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java	12 Aug 2003 20:20:04 -0000	1.3
+++ index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java	2 Feb 2004 10:17:45 -0000
@@ -128,8 +128,12 @@
 	 */
 	public void mapRefs(int[] mappings) {
 		int position= 0;
+
 		for (int i= 0; i < fNumRefs; i++) {
-			int map= mappings[fRefs[i]];
+			//Take care that the reference is actually within the bounds of the mapping
+			int map= -1;
+			if(fRefs[i] >= 0 && fRefs[i] < mappings.length) 
+				map= mappings[fRefs[i]];
 			if (map != -1 && map != 0)
 				fRefs[position++]= map;
 		}

Back to the top