summaryrefslogtreecommitdiff
path: root/core/include/fxcrt
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-01-07 12:31:41 -0800
committerTom Sepez <tsepez@chromium.org>2015-01-07 12:31:41 -0800
commit310d26aadffd2f3141b683f40010109a455b403a (patch)
tree723b4aa48247af51a6caed52958e41350499a36e /core/include/fxcrt
parent948095edfc04f35a69f15cd7d9926844ee0ac624 (diff)
downloadpdfium-310d26aadffd2f3141b683f40010109a455b403a.tar.xz
Finish unit test for CFX_ByteStringC class.
This fixes a few cut-n-paste errors in the previous version, plus adds more corner cases. The implementation is fixed to handle a few of these that failed. R=brucedawson@chromium.org Review URL: https://codereview.chromium.org/808553013
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r--core/include/fxcrt/fx_string.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 524d7efde5..eae1c15a04 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -15,6 +15,9 @@ class CFX_BinaryBuf;
typedef int FX_STRSIZE;
class CFX_ByteStringL;
class CFX_WideStringL;
+
+// An immutable string with caller-provided storage which must outlive the
+// string itself.
class CFX_ByteStringC : public CFX_Object
{
public:
@@ -38,6 +41,13 @@ public:
m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0;
}
+ // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However,
+ // the use of char rvalues are not caught at compile time. They are
+ // implicitly promoted to CFX_ByteString (see below) and then the
+ // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate
+ // constructor below. The CFX_ByteString then typically goes out of scope
+ // and |m_Ptr| may be left pointing to invalid memory. Beware.
+ // TODO(tsepez): Mark single-argument string constructors as explicit.
CFX_ByteStringC(FX_CHAR& ch)
{
m_Ptr = (FX_LPCBYTE)&ch;
@@ -65,7 +75,7 @@ public:
CFX_ByteStringC& operator = (FX_LPCSTR src)
{
m_Ptr = (FX_LPCBYTE)src;
- m_Length = (FX_STRSIZE)FXSYS_strlen(src);
+ m_Length = m_Ptr ? (FX_STRSIZE)FXSYS_strlen(src) : 0;
return *this;
}