Skip to content

Commit

Permalink
Simplify null terminator handling in DictionaryProperty.Write
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy authored and jeremy-visionaid committed Nov 19, 2024
1 parent c1825a1 commit f950d38
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions OpenMcdf.Ole/DictionaryProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,36 +104,23 @@ private void WriteEntry(BinaryWriter bw, uint propertyIdentifier, string name)
// In either case, the string must be null terminated
if (codePage == CodePages.WinUnicode)
{
bool addNullTerminator =
byteLength == 0 || nameBytes[byteLength - 1] != '\0' || nameBytes[byteLength - 2] != '\0';

if (addNullTerminator)
byteLength += 2;
// Two bytes padding for Unicode strings
byteLength += 2;

bw.Write(byteLength / 2);
bw.Write(nameBytes);

if (addNullTerminator)
{
bw.Write((byte)0);
bw.Write((byte)0);
}
bw.Write((byte)0);
bw.Write((byte)0);

WritePaddingIfNeeded(bw, (int)byteLength);
}
else
{
bool addNullTerminator =
byteLength == 0 || nameBytes[byteLength - 1] != '\0';

if (addNullTerminator)
byteLength += 1;
byteLength += 1;

bw.Write(byteLength);
bw.Write(nameBytes);

if (addNullTerminator)
bw.Write((byte)0);
bw.Write((byte)0);
}
}

Expand Down

0 comments on commit f950d38

Please sign in to comment.