summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-20 15:09:19 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-20 19:53:20 +0000
commit3f753f20e9c51f7170a616a355b3f9578505c0ee (patch)
tree5a8e90f1860716003a2d63d37597ff5d592ae84d
parentbba6b77b6b35da6b5884248d768f12615f62a003 (diff)
downloadpdfium-3f753f20e9c51f7170a616a355b3f9578505c0ee.tar.xz
Change length calculation in CFX_StringCTemplate constructor
Originally this would only calculate the length of the passed in string if the passed in length was -1. This causes issues, since other negative values will be passed straight through and break the post-condition on the constructor of the length being non-negative. This leads to undefined and hard to debug behaviour later, in cases where the root cause is a mistake in calculating the proper length. The other related classes, CFX_WideString & CFX_ByteString, test for all negative length values and calculating the length when they occur. This CL changes the FooC versions to use this logic. This implicitly assumes the string is null terminated, so in the incase of an incorrect negative length and a non-null terminated string there will still be a crash, but it will now occur at construction time, instead of at some random later time. BUG=pdfium:827 Change-Id: I4d1fed746ada67c496d8e6ab10861b9332555023 Reviewed-on: https://pdfium-review.googlesource.com/8450 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--core/fxcrt/cfx_string_c_template.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h
index 1473160334..cd3cd27e75 100644
--- a/core/fxcrt/cfx_string_c_template.h
+++ b/core/fxcrt/cfx_string_c_template.h
@@ -35,7 +35,7 @@ class CFX_StringCTemplate {
CFX_StringCTemplate(const CharType* ptr, FX_STRSIZE len)
: m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)),
- m_Length(len == -1 ? FXSYS_len(ptr) : len) {}
+ m_Length(len < 0 ? FXSYS_len(ptr) : len) {}
template <typename U = UnsignedType>
CFX_StringCTemplate(