From d524e4bf80314ade4a6aedf77b8b4adaa96bfcee Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 25 Apr 2017 09:43:52 -0700 Subject: Delete some CFX string ctors. Prevent implicit construction of CFX_WideString from non-wchar_t variables. Similarly prevent implicit construction of CFX_ByteString from non-char variables. Fix up CBC_OnedCodaBarWriter which tries to do the above, and simplify code there using pdfium::ContainsValue(). Same for CPDF_FileSpec. Change-Id: I3db7125a68ef3f64c2f235d38e974767cd083dc3 Reviewed-on: https://pdfium-review.googlesource.com/4478 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fpdfdoc/cpdf_filespec.cpp | 43 +++++++++++++++++------------------------- core/fxcrt/cfx_bytestring.h | 4 ++++ core/fxcrt/cfx_widestring.h | 4 ++++ 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'core') diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp index e5f026e573..086515b9a8 100644 --- a/core/fpdfdoc/cpdf_filespec.cpp +++ b/core/fpdfdoc/cpdf_filespec.cpp @@ -22,9 +22,9 @@ CFX_WideString ChangeSlashToPlatform(const wchar_t* str) { while (*str) { if (*str == '/') { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - result += ':'; + result += L':'; #else - result += '\\'; + result += L'\\'; #endif } else { result += *str; @@ -38,7 +38,7 @@ CFX_WideString ChangeSlashToPDF(const wchar_t* str) { CFX_WideString result; while (*str) { if (*str == '\\' || *str == ':') - result += '/'; + result += L'/'; else result += *str; @@ -60,19 +60,19 @@ CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideStringC& filepath) { return ChangeSlashToPlatform(filepath.c_str()); #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (filepath.GetAt(0) != '/') + if (filepath.GetAt(0) != L'/') return ChangeSlashToPlatform(filepath.c_str()); - if (filepath.GetAt(1) == '/') + if (filepath.GetAt(1) == L'/') return ChangeSlashToPlatform(filepath.c_str() + 1); - if (filepath.GetAt(2) == '/') { + if (filepath.GetAt(2) == L'/') { CFX_WideString result; result += filepath.GetAt(1); - result += ':'; + result += L':'; result += ChangeSlashToPlatform(filepath.c_str() + 2); return result; } CFX_WideString result; - result += '\\'; + result += L'\\'; result += ChangeSlashToPlatform(filepath.c_str()); return result; #else @@ -122,33 +122,24 @@ CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { return CFX_WideString(); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (filepath.GetAt(1) == ':') { - CFX_WideString result; - result = '/'; + if (filepath.GetAt(1) == L':') { + CFX_WideString result(L'/'); result += filepath.GetAt(0); - if (filepath.GetAt(2) != '\\') - result += '/'; + if (filepath.GetAt(2) != L'\\') + result += L'/'; result += ChangeSlashToPDF(filepath.c_str() + 2); return result; } - if (filepath.GetAt(0) == '\\' && filepath.GetAt(1) == '\\') + if (filepath.GetAt(0) == L'\\' && filepath.GetAt(1) == L'\\') return ChangeSlashToPDF(filepath.c_str() + 1); - if (filepath.GetAt(0) == '\\') { - CFX_WideString result; - result = '/'; - result += ChangeSlashToPDF(filepath.c_str()); - return result; - } + if (filepath.GetAt(0) == L'\\') + return L'/' + ChangeSlashToPDF(filepath.c_str()); return ChangeSlashToPDF(filepath.c_str()); #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - if (filepath.Left(sizeof("Mac") - 1) == L"Mac") { - CFX_WideString result; - result = '/'; - result += ChangeSlashToPDF(filepath.c_str()); - return result; - } + if (filepath.Left(sizeof("Mac") - 1) == L"Mac") + return L'/' + ChangeSlashToPDF(filepath.c_str()); return ChangeSlashToPDF(filepath.c_str()); #else return CFX_WideString(filepath); diff --git a/core/fxcrt/cfx_bytestring.h b/core/fxcrt/cfx_bytestring.h index 0ffe92936a..c4d48954ba 100644 --- a/core/fxcrt/cfx_bytestring.h +++ b/core/fxcrt/cfx_bytestring.h @@ -35,6 +35,10 @@ class CFX_ByteString { // NOLINTNEXTLINE(runtime/explicit) CFX_ByteString(const char* ptr); + // No implicit conversions from wide strings. + // NOLINTNEXTLINE(runtime/explicit) + CFX_ByteString(wchar_t) = delete; + CFX_ByteString(const char* ptr, FX_STRSIZE len); CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len); diff --git a/core/fxcrt/cfx_widestring.h b/core/fxcrt/cfx_widestring.h index fd3c92a15e..977114816d 100644 --- a/core/fxcrt/cfx_widestring.h +++ b/core/fxcrt/cfx_widestring.h @@ -35,6 +35,10 @@ class CFX_WideString { // NOLINTNEXTLINE(runtime/explicit) CFX_WideString(const wchar_t* ptr); + // No implicit conversions from byte strings. + // NOLINTNEXTLINE(runtime/explicit) + CFX_WideString(char) = delete; + CFX_WideString(const wchar_t* ptr, FX_STRSIZE len); explicit CFX_WideString(const CFX_WideStringC& str); -- cgit v1.2.3