]> source.dussan.org Git - poi.git/commitdiff
ignore CHPX references zero-length text pieces
authorSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 18:34:26 +0000 (18:34 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 18:34:26 +0000 (18:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145275 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java

index 714f0e1c1e8b9f7f1e7087d10cec6743fb7aba4b..0dd077ad8e7ec96a1f127832454e070f4e4aea10 100644 (file)
@@ -74,31 +74,42 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
      * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array
      * read from a Word file).
      */
-    public CHPFormattedDiskPage( byte[] documentStream, int offset, TextPieceTable tpt,
-            boolean ignoreChpxWithoutTextPieces )
+    public CHPFormattedDiskPage( byte[] documentStream, int offset,
+            TextPieceTable tpt, boolean ignoreChpxWithoutTextPieces )
     {
-      super(documentStream, offset);
+        super( documentStream, offset );
 
-      for (int x = 0; x < _crun; x++)
-      {
-       int startAt = getStart(x);
-               int endAt = getEnd(x);
-
-        if (!ignoreChpxWithoutTextPieces || tpt.isIndexInTable( startAt, endAt ) )
-        {
-                   _chpxList.add(new CHPX(startAt, endAt, tpt, getGrpprl(x)));
-        }
-        else
+        for ( int x = 0; x < _crun; x++ )
         {
-            logger.log( POILogger.WARN, "CHPX [",
-                    Integer.valueOf( startAt ), "; ",
-                    Integer.valueOf( endAt ),
-                    ") (bytes) doesn't have corresponding text pieces "
-                            + "and will be skipped" );
-
-            _chpxList.add(null);
+            int startAt = getStart( x );
+            int endAt = getEnd( x );
+
+            if ( ignoreChpxWithoutTextPieces
+                    && !tpt.isIndexInTable( startAt, endAt ) )
+            {
+                logger.log( POILogger.WARN, "CHPX [",
+                        Integer.valueOf( startAt ), "; ",
+                        Integer.valueOf( endAt ),
+                        ") (bytes) doesn't have corresponding text pieces "
+                                + "and will be skipped" );
+
+                _chpxList.add( null );
+                continue;
+            }
+
+            CHPX chpx = new CHPX( startAt, endAt, tpt, getGrpprl( x ) );
+
+            if ( ignoreChpxWithoutTextPieces
+                    && chpx.getStart() == chpx.getEnd() )
+            {
+                logger.log( POILogger.WARN, chpx
+                        + " references zero-length range and will be skipped" );
+                _chpxList.add( null );
+                continue;
+            }
+
+            _chpxList.add( chpx );
         }
-      }
     }
 
     public CHPX getCHPX(int index)