Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2980)

Unified Diff: core/include/fxcrt/fx_string.h

Issue 808553013: Finish unit test for CFX_ByteStringC class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Soften up comment Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | core/src/fxcrt/fx_basic_bstring_unittest.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/include/fxcrt/fx_string.h
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 91032f9d9773b4e955d6dc6218454739f1aab69d..0c9a2e97e3f5fd03a89331a10167eb81302a3776 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -37,6 +37,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.
brucedawson 2015/01/06 18:27:21 Perhaps put a comment above the class declaration
Tom Sepez 2015/01/06 18:45:21 Done. Much better.
CFX_ByteStringC(FX_CHAR& ch)
{
m_Ptr = (FX_LPCBYTE)&ch;
@@ -64,7 +71,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;
}
« no previous file with comments | « no previous file | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | core/src/fxcrt/fx_basic_bstring_unittest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698