From: James Ahlborn Date: Tue, 15 Apr 2008 02:49:03 +0000 (+0000) Subject: put entry validation inline with entry reading X-Git-Tag: rel_1_1_14~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a341781aa419d9b6eec105dc8a5d59ff52138e41;p=jackcess.git put entry validation inline with entry reading git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@326 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 9eb3ca1..ec3629d 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -806,6 +806,7 @@ public abstract class Index implements Comparable { TempBufferHolder.newHolder(TempBufferHolder.Type.HARD, true, ByteOrder.BIG_ENDIAN); + Entry prevEntry = FIRST_ENTRY; for (int i = 0; i < entryMaskLength; i++) { byte entryMask = buffer.get(entryMaskPos + i); for (int j = 0; j < 8; j++) { @@ -823,8 +824,14 @@ public abstract class Index implements Comparable { curEntryLen += entryPrefix.length; } totalEntrySize += curEntryLen; + + Entry entry = newEntry(curEntryBuffer, curEntryLen, isLeaf); + if(prevEntry.compareTo(entry) >= 0) { + throw new IOException("Unexpected order in index entries, " + + prevEntry + " >= " + entry); + } - entries.add(newEntry(curEntryBuffer, curEntryLen, isLeaf)); + entries.add(entry); if(entries.size() == 1) { if(entryPrefixLength > 0) { @@ -836,19 +843,10 @@ public abstract class Index implements Comparable { } lastStart += length; + prevEntry = entry; } } } - - // check the entry order, just to be safe - for(int i = 0; i < (entries.size() - 1); ++i) { - Entry e1 = entries.get(i); - Entry e2 = entries.get(i + 1); - if(e1.compareTo(e2) > 0) { - throw new IOException("Unexpected order in index entries, " + - e1 + " is greater than " + e2); - } - } dataPage.setEntryPrefix(entryPrefix != null ? entryPrefix : EMPTY_PREFIX); dataPage.setEntries(entries);