]> source.dussan.org Git - poi.git/commitdiff
Fixed zero length Label string reading
authorJason Height <jheight@apache.org>
Wed, 17 Sep 2003 05:34:29 +0000 (05:34 +0000)
committerJason Height <jheight@apache.org>
Wed, 17 Sep 2003 05:34:29 +0000 (05:34 +0000)
Fixed incorrect offset for uncompressed unicode

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353355 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/LabelRecord.java

index 950a7cc0936fef63a3d33045dc97a626150d5582..7c58edd08fd1c6808d3c8c0c75af8949cdc90af2 100644 (file)
@@ -150,15 +150,17 @@ public class LabelRecord
         field_3_xf_index     = LittleEndian.getShort(data, 4 + offset);
         field_4_string_len   = LittleEndian.getShort(data, 6 + offset);
         field_5_unicode_flag = data[ 8 + offset ];
-        if (isUnCompressedUnicode())
-        {
-            field_6_value = StringUtil.getFromUnicodeBE(data, 8 + offset,
-                                                      field_4_string_len);
-        }
-        else
-        {
-            field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, getStringLength());
-        }
+        if (field_4_string_len > 0) {
+          if (isUnCompressedUnicode())
+          {
+              field_6_value = StringUtil.getFromUnicodeBE(data, 9 + offset,
+                                                        field_4_string_len);
+          }
+          else
+          {
+              field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, getStringLength());
+          }
+        } else field_6_value = null;
     }
 
 /* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST!
@@ -237,6 +239,27 @@ public class LabelRecord
         return this.sid;
     }
 
+    public String toString()
+    {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("[LABEL]\n");
+        buffer.append("    .row            = ")
+            .append(Integer.toHexString(getRow())).append("\n");
+        buffer.append("    .column         = ")
+            .append(Integer.toHexString(getColumn())).append("\n");
+        buffer.append("    .xfindex        = ")
+            .append(Integer.toHexString(getXFIndex())).append("\n");
+        buffer.append("    .string_len       = ")
+            .append(Integer.toHexString(field_4_string_len)).append("\n");
+        buffer.append("    .unicode_flag       = ")
+            .append(Integer.toHexString(field_5_unicode_flag)).append("\n");
+        buffer.append("    .value       = ")
+            .append(getValue()).append("\n");
+        buffer.append("[/LABEL]\n");
+        return buffer.toString();
+    }
+
+
     public boolean isBefore(CellValueRecordInterface i)
     {
         if (this.getRow() > i.getRow())