Round sizes to 16 bytes in StringDataTemplate::Create().
Since PartitionAlloc underneath is using 16 bytes chunks.
Change-Id: I070efa6f3a2371a28f78c68a636d398f4c1d3d8e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69072
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/string_data_template.cpp b/core/fxcrt/string_data_template.cpp
index a7cafd2..d884869 100644
--- a/core/fxcrt/string_data_template.cpp
+++ b/core/fxcrt/string_data_template.cpp
@@ -25,12 +25,12 @@
nSize *= sizeof(CharType);
nSize += overhead;
- // Now round to an 8-byte boundary. We'd expect that this is the minimum
- // granularity of any of the underlying allocators, so there may be cases
- // where we can save a re-alloc when adding a few characters to a string
- // by using this otherwise wasted space.
- nSize += 7;
- nSize &= ~7;
+ // Now round to an 16-byte boundary, assuming the underlying allocator is most
+ // likely PartitionAlloc, which has 16 byte chunks. This will help with cases
+ // where we can save a re-alloc when adding a few characters to a string by
+ // using this otherwise wasted space.
+ nSize += 15;
+ nSize &= ~15;
size_t totalSize = nSize.ValueOrDie();
size_t usableLen = (totalSize - overhead) / sizeof(CharType);
ASSERT(usableLen >= nLen);