]> source.dussan.org Git - jackcess.git/commitdiff
Fix bug caused by sign extension when reading single-byte row numbers; fix some bugs...
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 7 Mar 2008 19:23:46 +0000 (19:23 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 7 Mar 2008 19:23:46 +0000 (19:23 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@252 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/java/com/healthmarketscience/jackcess/Column.java
src/java/com/healthmarketscience/jackcess/Index.java
src/java/com/healthmarketscience/jackcess/PageChannel.java
src/java/com/healthmarketscience/jackcess/Table.java
src/java/com/healthmarketscience/jackcess/UsageMap.java

index 4b1add120489e101264e55267f9bfa2e6eb216c1..767da5fe451d737d51a03b1f585667528d63ea6b 100644 (file)
@@ -18,6 +18,9 @@
         Expand the characters supported in index updates to all of the
         ISO-8859-1 character set.
       </action>
+      <action dev="jahlborn" type="update">
+        Fix bug caused by sign extension when reading single-byte row numbers.
+      </action>
     </release>
     <release version="1.1.12" date="2008-02-27">
       <action dev="jahlborn" type="fix">
index 6f05cea098238bc7c5d9c16e4daf9eee8d7f0d6e..19127875c34aeeaa62142a3b1dd5c1c0d3976405 100644 (file)
@@ -451,7 +451,7 @@ public class Column implements Comparable<Column> {
                               lvalDefinition.length);
       }
 
-      byte rowNum = def.get();
+      int rowNum = ByteUtil.toUnsignedInt(def.get());
       int pageNum = ByteUtil.get3ByteInt(def, def.position());
       ByteBuffer lvalPage = getPageChannel().createPageBuffer();
       
@@ -485,7 +485,7 @@ public class Column implements Comparable<Column> {
           
           // read next page information
           lvalPage.position(rowStart);
-          rowNum = lvalPage.get();
+          rowNum = ByteUtil.toUnsignedInt(lvalPage.get());
           pageNum = ByteUtil.get3ByteInt(lvalPage);
 
           // update rowEnd and remainingLen based on chunkLength
index 2a4695922a984bfff1c1f19e4dbb6622ef2ab76a..eb57194b19029c04397dd667c6ed7351cb9bf97b 100644 (file)
@@ -948,6 +948,7 @@ public class Index implements Comparable<Index> {
             ++charOffset;
           }
           tmpBout.write(extraCodes._extraCodes);
+          ++charOffset;
         }
       }
 
@@ -988,7 +989,7 @@ public class Index implements Comparable<Index> {
     }
 
     // write end extra text
-    tmpBout.write(END_EXTRA_TEXT);    
+    bout.write(END_EXTRA_TEXT);    
   }
 
   /**
@@ -1295,7 +1296,8 @@ public class Index implements Comparable<Index> {
 
       // read the rowId
       int page = ByteUtil.get3ByteInt(buffer, ByteOrder.BIG_ENDIAN);
-      int row = buffer.get();
+      int row = ByteUtil.toUnsignedInt(buffer.get());
+      
       _rowId = new RowId(page, row);
       _type = EntryType.NORMAL;
     }
index cd4bd43fa49cc346a3b074aaf5a5cb14949f61bf..5a94c3990c66cc950cdc43ace0646509c7e136a4 100644 (file)
@@ -52,6 +52,8 @@ public class PageChannel implements Channel, Flushable {
   
   /** Global usage map always lives on page 1 */
   private static final int PAGE_GLOBAL_USAGE_MAP = 1;
+  /** Global usage map always lives at row 0 */
+  private static final int ROW_GLOBAL_USAGE_MAP = 0;
   
   /** Channel containing the database */
   private final FileChannel _channel;
@@ -82,8 +84,8 @@ public class PageChannel implements Channel, Flushable {
   {
     // note the global usage map is a special map where any page outside of
     // the current range is assumed to be "on"
-    _globalUsageMap = UsageMap.read(database, PAGE_GLOBAL_USAGE_MAP, (byte) 0,
-                                    true);
+    _globalUsageMap = UsageMap.read(database, PAGE_GLOBAL_USAGE_MAP,
+                                    ROW_GLOBAL_USAGE_MAP, true);
   }
   
   /**
index 8ec92d4e256d0e8eb5c75261fbf8b4f0b0ec5a9a..b87698ebe6a31f3a62d5d0a0f56e4592f9ef5cb9 100644 (file)
@@ -580,7 +580,7 @@ public class Table
       
         // Overflow page.  the "row" data in the current page points to
         // another page/row
-        int overflowRowNum = rowBuffer.get(rowStart);
+        int overflowRowNum = ByteUtil.toUnsignedInt(rowBuffer.get(rowStart));
         int overflowPageNum = ByteUtil.get3ByteInt(rowBuffer, rowStart + 1);
         rowBuffer = rowState.setOverflowRow(
             new RowId(overflowPageNum, overflowRowNum));
@@ -915,10 +915,12 @@ public class Table
     _indexSlotCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEX_SLOTS);
     _indexCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEXES);
 
-    byte rowNum = tableBuffer.get(getFormat().OFFSET_OWNED_PAGES);
+    int rowNum = ByteUtil.toUnsignedInt(
+        tableBuffer.get(getFormat().OFFSET_OWNED_PAGES));
     int pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_OWNED_PAGES + 1);
     _ownedPages = UsageMap.read(getDatabase(), pageNum, rowNum, false);
-    rowNum = tableBuffer.get(getFormat().OFFSET_FREE_SPACE_PAGES);
+    rowNum = ByteUtil.toUnsignedInt(
+        tableBuffer.get(getFormat().OFFSET_FREE_SPACE_PAGES));
     pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_FREE_SPACE_PAGES + 1);
     _freeSpacePages = UsageMap.read(getDatabase(), pageNum, rowNum, false);
     
index bdc0fd4b3017abee5aca52cd5087944f1b05fc2e..a6b81ade8bdf50b2a74f05bc88589e4cde98778c 100644 (file)
@@ -115,7 +115,7 @@ public class UsageMap
    *         which type of map is found
    */
   public static UsageMap read(Database database, int pageNum,
-                              byte rowNum, boolean assumeOutOfRangeBitsOn)
+                              int rowNum, boolean assumeOutOfRangeBitsOn)
     throws IOException
   {
     JetFormat format = database.getFormat();