summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-16 12:03:24 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-16 12:03:24 -0700
commit3f80c864d5318d4d80ac811d42c92d8f63e0b5ac (patch)
treeefc4acca871bfb2fb1af80f5ee5779ac6ef70034 /fpdfsdk/fpdfxfa
parentb22504a8c589ff39a1d6eaa83dcd3ead454d3443 (diff)
downloadpdfium-3f80c864d5318d4d80ac811d42c92d8f63e0b5ac.tar.xz
Remove some c_str() calls from StringCs in xfa docs.
Avoids the risk of possibly getting a non-null terminated buffer if the StringC happened to be created by Mid(), etc. Doesn't seem to happen in practice. Review-Url: https://codereview.chromium.org/1983683003
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_app.cpp60
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp21
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_app.h31
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h6
4 files changed, 56 insertions, 62 deletions
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp
index f9c3ca65a3..e91bdf1699 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp
@@ -131,8 +131,8 @@ void CPDFXFA_App::Beep(uint32_t dwType) {
}
}
-int32_t CPDFXFA_App::MsgBox(const CFX_WideStringC& wsMessage,
- const CFX_WideStringC& wsTitle,
+int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
+ const CFX_WideString& wsTitle,
uint32_t dwIconType,
uint32_t dwButtonType) {
CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
@@ -184,11 +184,11 @@ int32_t CPDFXFA_App::MsgBox(const CFX_WideStringC& wsMessage,
return XFA_IDYes;
}
-void CPDFXFA_App::Response(CFX_WideString& wsAnswer,
- const CFX_WideStringC& wsQuestion,
- const CFX_WideStringC& wsTitle,
- const CFX_WideStringC& wsDefaultAnswer,
- FX_BOOL bMark) {
+CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion,
+ const CFX_WideString& wsTitle,
+ const CFX_WideString& wsDefaultAnswer,
+ FX_BOOL bMark) {
+ CFX_WideString wsAnswer;
CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
if (pEnv) {
int nLength = 2048;
@@ -206,6 +206,7 @@ void CPDFXFA_App::Response(CFX_WideString& wsAnswer,
}
delete[] pBuff;
}
+ return wsAnswer;
}
int32_t CPDFXFA_App::GetCurDocumentInBatch() {
@@ -225,39 +226,34 @@ int32_t CPDFXFA_App::GetDocumentCountInBatch() {
return 0;
}
-IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideStringC& wsURL) {
+IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) {
CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
- if (pEnv) {
- return pEnv->FFI_DownloadFromURL(wsURL.c_str());
- }
- return NULL;
+ return pEnv ? pEnv->FFI_DownloadFromURL(wsURL.c_str()) : nullptr;
}
-FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideStringC& wsURL,
- const CFX_WideStringC& wsData,
- const CFX_WideStringC& wsContentType,
- const CFX_WideStringC& wsEncode,
- const CFX_WideStringC& wsHeader,
+FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
+ const CFX_WideString& wsData,
+ const CFX_WideString& wsContentType,
+ const CFX_WideString& wsEncode,
+ const CFX_WideString& wsHeader,
CFX_WideString& wsResponse) {
CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
- if (pEnv) {
- wsResponse = pEnv->FFI_PostRequestURL(wsURL.c_str(), wsData.c_str(),
- wsContentType.c_str(),
- wsEncode.c_str(), wsHeader.c_str());
- return TRUE;
- }
- return FALSE;
+ if (!pEnv)
+ return FALSE;
+
+ wsResponse = pEnv->FFI_PostRequestURL(wsURL.c_str(), wsData.c_str(),
+ wsContentType.c_str(), wsEncode.c_str(),
+ wsHeader.c_str());
+ return TRUE;
}
-FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideStringC& wsURL,
- const CFX_WideStringC& wsData,
- const CFX_WideStringC& wsEncode) {
+FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL,
+ const CFX_WideString& wsData,
+ const CFX_WideString& wsEncode) {
CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
- if (pEnv) {
- return pEnv->FFI_PutRequestURL(wsURL.c_str(), wsData.c_str(),
- wsEncode.c_str());
- }
- return FALSE;
+ return pEnv &&
+ pEnv->FFI_PutRequestURL(wsURL.c_str(), wsData.c_str(),
+ wsEncode.c_str());
}
void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
index deba943072..b2f752e8b9 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
@@ -625,21 +625,22 @@ void CPDFXFA_Document::SetTitle(CXFA_FFDoc* hDoc,
}
void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc,
- const CFX_WideStringC& wsFilePath,
+ const CFX_WideString& wsFilePath,
FX_BOOL bXDP) {
if (hDoc != m_pXFADoc)
return;
+
if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
return;
+
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (pEnv == NULL)
+ if (!pEnv)
return;
- int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML;
- CFX_ByteString bs = CFX_WideString(wsFilePath).UTF16LE_Encode();
+ int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML;
+ CFX_ByteString bs = wsFilePath.UTF16LE_Encode();
if (wsFilePath.IsEmpty()) {
- if (!pEnv->GetFormFillInfo() ||
- pEnv->GetFormFillInfo()->m_pJsPlatform == NULL)
+ if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform)
return;
CFX_WideString filepath = pEnv->JS_fieldBrowse();
bs = filepath.UTF16LE_Encode();
@@ -649,12 +650,10 @@ void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc,
bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
(FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "wb");
bs.ReleaseBuffer(len * sizeof(unsigned short));
-
- if (pFileHandler == NULL)
+ if (!pFileHandler)
return;
CFPDF_FileStream fileWrite(pFileHandler);
-
CFX_ByteString content;
if (fileType == FXFA_SAVEAS_XML) {
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
@@ -725,10 +724,10 @@ void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc,
}
}
void CPDFXFA_Document::ImportData(CXFA_FFDoc* hDoc,
- const CFX_WideStringC& wsFilePath) {}
+ const CFX_WideString& wsFilePath) {}
void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc,
- const CFX_WideStringC& bsURL,
+ const CFX_WideString& bsURL,
FX_BOOL bAppend) {
if (hDoc != m_pXFADoc)
return;
diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h
index 6491781cbe..3a61ef40c3 100644
--- a/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h
+++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h
@@ -51,29 +51,28 @@ class CPDFXFA_App : public IXFA_AppProvider {
}
void Beep(uint32_t dwType) override;
- int32_t MsgBox(const CFX_WideStringC& wsMessage,
- const CFX_WideStringC& wsTitle,
+ int32_t MsgBox(const CFX_WideString& wsMessage,
+ const CFX_WideString& wsTitle,
uint32_t dwIconType,
uint32_t dwButtonType) override;
- void Response(CFX_WideString& wsAnswer,
- const CFX_WideStringC& wsQuestion,
- const CFX_WideStringC& wsTitle,
- const CFX_WideStringC& wsDefaultAnswer,
- FX_BOOL bMark) override;
+ CFX_WideString Response(const CFX_WideString& wsQuestion,
+ const CFX_WideString& wsTitle,
+ const CFX_WideString& wsDefaultAnswer,
+ FX_BOOL bMark) override;
int32_t GetDocumentCountInBatch() override;
int32_t GetCurDocumentInBatch() override;
- IFX_FileRead* DownloadURL(const CFX_WideStringC& wsURL) override;
- FX_BOOL PostRequestURL(const CFX_WideStringC& wsURL,
- const CFX_WideStringC& wsData,
- const CFX_WideStringC& wsContentType,
- const CFX_WideStringC& wsEncode,
- const CFX_WideStringC& wsHeader,
+ IFX_FileRead* DownloadURL(const CFX_WideString& wsURL) override;
+ FX_BOOL PostRequestURL(const CFX_WideString& wsURL,
+ const CFX_WideString& wsData,
+ const CFX_WideString& wsContentType,
+ const CFX_WideString& wsEncode,
+ const CFX_WideString& wsHeader,
CFX_WideString& wsResponse) override;
- FX_BOOL PutRequestURL(const CFX_WideStringC& wsURL,
- const CFX_WideStringC& wsData,
- const CFX_WideStringC& wsEncode) override;
+ FX_BOOL PutRequestURL(const CFX_WideString& wsURL,
+ const CFX_WideString& wsData,
+ const CFX_WideString& wsEncode) override;
void LoadString(int32_t iStringID, CFX_WideString& wsString) override;
IFWL_AdapterTimerMgr* GetTimerMgr() override;
diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
index a67b7803a0..416e4b9de3 100644
--- a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
+++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h
@@ -92,11 +92,11 @@ class CPDFXFA_Document : public IXFA_DocProvider {
virtual void GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle);
virtual void SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle);
virtual void ExportData(CXFA_FFDoc* hDoc,
- const CFX_WideStringC& wsFilePath,
+ const CFX_WideString& wsFilePath,
FX_BOOL bXDP = TRUE);
- virtual void ImportData(CXFA_FFDoc* hDoc, const CFX_WideStringC& wsFilePath);
+ virtual void ImportData(CXFA_FFDoc* hDoc, const CFX_WideString& wsFilePath);
virtual void GotoURL(CXFA_FFDoc* hDoc,
- const CFX_WideStringC& bsURL,
+ const CFX_WideString& bsURL,
FX_BOOL bAppend = TRUE);
virtual FX_BOOL IsValidationsEnabled(CXFA_FFDoc* hDoc);
virtual void SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled);