Add WARN_UNUSED_RESULT to more static methods in (Byte|Wide)String.
Also fixes some usages that were not working as intended after the
conversion to static.
Change-Id: I18c18369754f6ca165f98999b5b80eecf6c76973
Reviewed-on: https://pdfium-review.googlesource.com/20590
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index 6b16780..9168206 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -64,7 +64,7 @@
void clear() { m_pData.Reset(); }
- static ByteString FromUnicode(const WideString& str);
+ static ByteString FromUnicode(const WideString& str) WARN_UNUSED_RESULT;
// Explicit conversion to C-style string.
// Note: Any subsequent modification of |this| will invalidate the result.
diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h
index 14621ec..728ab35 100644
--- a/core/fxcrt/widestring.h
+++ b/core/fxcrt/widestring.h
@@ -33,8 +33,9 @@
using const_iterator = const CharType*;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
- static WideString Format(const wchar_t* lpszFormat, ...);
- static WideString FormatV(const wchar_t* lpszFormat, va_list argList);
+ static WideString Format(const wchar_t* lpszFormat, ...) WARN_UNUSED_RESULT;
+ static WideString FormatV(const wchar_t* lpszFormat,
+ va_list argList) WARN_UNUSED_RESULT;
WideString();
WideString(const WideString& other);
@@ -58,13 +59,15 @@
~WideString();
- static WideString FromLocal(const ByteStringView& str);
- static WideString FromCodePage(const ByteStringView& str, uint16_t codepage);
+ static WideString FromLocal(const ByteStringView& str) WARN_UNUSED_RESULT;
+ static WideString FromCodePage(const ByteStringView& str,
+ uint16_t codepage) WARN_UNUSED_RESULT;
- static WideString FromUTF8(const ByteStringView& str);
- static WideString FromUTF16LE(const unsigned short* str, size_t len);
+ static WideString FromUTF8(const ByteStringView& str) WARN_UNUSED_RESULT;
+ static WideString FromUTF16LE(const unsigned short* str,
+ size_t len) WARN_UNUSED_RESULT;
- static size_t WStringLength(const unsigned short* str);
+ static size_t WStringLength(const unsigned short* str) WARN_UNUSED_RESULT;
// Explicit conversion to C-style wide string.
// Note: Any subsequent modification of |this| will invalidate the result.
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index 39337aa..1673c8f 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -1330,7 +1330,7 @@
}
TEST(WideString, FormatOutOfRangeChar) {
- WideString::Format(L"unsupported char '%c'", 0x00FF00FF);
+ EXPECT_NE(L"", WideString::Format(L"unsupported char '%c'", 0x00FF00FF));
}
TEST(WideString, Empty) {
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 9043124..70b0f1b 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -642,8 +642,7 @@
if (!pFormFillEnv)
return false;
- WideString ws;
- ws.FromLocal(IDS_XFA_Validate_Input);
+ WideString ws = WideString::FromLocal(IDS_XFA_Validate_Input);
ByteString bs = ws.UTF16LE_Encode();
int len = bs.GetLength();
pFormFillEnv->Alert((FPDF_WIDESTRING)bs.GetBuffer(len),
@@ -902,8 +901,7 @@
WideString csURL = submitData.GetSubmitTarget();
if (csURL.IsEmpty()) {
- WideString ws;
- ws.FromLocal("Submit cancelled.");
+ WideString ws = WideString::FromLocal("Submit cancelled.");
ByteString bs = ws.UTF16LE_Encode();
int len = bs.GetLength();
pFormFillEnv->Alert(reinterpret_cast<FPDF_WIDESTRING>(bs.GetBuffer(len)),
@@ -919,8 +917,7 @@
WideString csContent = submitData.GetSubmitXDPContent();
csContent.Trim();
- WideString space;
- space.FromLocal(" ");
+ WideString space = WideString::FromLocal(" ");
csContent = space + csContent + space;
FPDF_DWORD flag = 0;
if (submitData.IsSubmitEmbedPDF())