From 3f753f20e9c51f7170a616a355b3f9578505c0ee Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 20 Jul 2017 15:09:19 -0400 Subject: 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 Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- core/fxcrt/cfx_string_c_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(ptr)), - m_Length(len == -1 ? FXSYS_len(ptr) : len) {} + m_Length(len < 0 ? FXSYS_len(ptr) : len) {} template CFX_StringCTemplate( -- cgit v1.2.3