From 7d3d6d01d71c692c14ecf4f3de6444a6ba23391e Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sun, 2 Oct 2011 00:55:56 +0000 Subject: [PATCH] correctly add padding to 16-bit integers git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1178111 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hpsf/VariantSupport.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index c01b3c57c5..c320435c29 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -477,11 +477,12 @@ public class VariantSupport extends Variant case Variant.VT_BOOL: { int trueOrFalse; - if (((Boolean) value).booleanValue()) - trueOrFalse = 1; + if ( ( (Boolean) value ).booleanValue() ) + trueOrFalse = 0xFFFF; else - trueOrFalse = 0; - length = TypeWriter.writeUIntToStream(out, trueOrFalse); + trueOrFalse = 0x0000; + TypeWriter.writeUShortToStream( out, trueOrFalse ); + length += 2; break; } case Variant.VT_LPSTR: @@ -534,7 +535,13 @@ public class VariantSupport extends Variant case Variant.VT_I2: { TypeWriter.writeToStream(out, ((Integer) value).shortValue()); - length = LittleEndianConsts.SHORT_SIZE; + // length = LittleEndianConsts.SHORT_SIZE; + TypeWriter.writeToStream( out, (short) 0x0000 ); + /* + * MUST be a 16-bit signed integer, followed by zero padding to 4 + * bytes -- http://msdn.microsoft.com/en-us/library/dd942532(v=PROT.13).aspx + */ + length = LittleEndianConsts.INT_SIZE; break; } case Variant.VT_I4: