summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-03-14 10:48:26 -0700
committerTom Sepez <tsepez@chromium.org>2016-03-14 10:48:26 -0700
commit54b0abed08048008498471e39b7c72b034474090 (patch)
tree11e35fc148fff5f1513669540122cbfdc88f7a17
parent764ec513eecbebd12781bcc96ce81ed5e736ee92 (diff)
downloadpdfium-54b0abed08048008498471e39b7c72b034474090.tar.xz
Fix offset outside bounds warning on GCC
Alterntive to part of https://codereview.chromium.org/1785943002/ BUG=589724 R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1802553004 .
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp2
-rw-r--r--core/include/fxcrt/fx_string.h18
2 files changed, 14 insertions, 6 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
index 62be48818b..f5464cc21e 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
@@ -471,7 +471,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList,
if (!pObj)
continue;
- CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1);
+ CFX_ByteStringC keyNoSlash(key.raw_str() + 1, key.GetLength() - 1);
pDict->SetAt(keyNoSlash, pObj);
}
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index d68fc2cb36..9b623b9e71 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -169,14 +169,22 @@ class CFX_ByteString {
static CFX_ByteString FromUnicode(const CFX_WideString& str);
- // Explicit conversion to raw string
+ // Explicit conversion to C-style string.
const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; }
- // Implicit conversion to C-style string -- deprecated
+ // Implicit conversion to C-style string -- deprecated.
operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; }
+ // Explicit conversion to uint8_t*.
+ const uint8_t* raw_str() const {
+ return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String)
+ : nullptr;
+ }
+
+ // Implicit conversiont to uint8_t* -- deprecated.
operator const uint8_t*() const {
- return m_pData ? (const uint8_t*)m_pData->m_String : NULL;
+ return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String)
+ : nullptr;
}
FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
@@ -569,10 +577,10 @@ class CFX_WideString {
static FX_STRSIZE WStringLength(const unsigned short* str);
- // Explicit conversion to raw string
+ // Explicit conversion to C-style wide string.
const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; }
- // Implicit conversion to C-style wide string -- deprecated
+ // Implicit conversion to C-style wide string -- deprecated.
operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; }
void Empty();