summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fpdfview.cpp
diff options
context:
space:
mode:
authorOliver Chang <ochang@chromium.org>2016-01-11 08:45:31 -0800
committerOliver Chang <ochang@chromium.org>2016-01-11 08:45:31 -0800
commit3f1c71f5a6ea058e3eec611c9dcc759b374dcb80 (patch)
treeb4ef8de26360979381c441cbdfaba94e493b09f6 /fpdfsdk/src/fpdfview.cpp
parentc909ce872d999a17ffd44afdc88caf2de43e6cba (diff)
downloadpdfium-3f1c71f5a6ea058e3eec611c9dcc759b374dcb80.tar.xz
Merge to XFA: Use std::map as CPDF_Dictionary's underlying store.
Replaces CFX_CMapByteStringToPtr. XFA still uses CFX_CMapByteStringToPtr so it's not completely removed just yet. Adds begin()/end() to CPDF_Dictionary and removes the GetStartPos()/GetNextElement() functions to traverse the dictionary. Callers are changed accordingly. AddValue() is also removed. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1541703003 . (cherry picked from commit 14f39950451bb9c2a11fbc7173fd47367410f80f) Review URL: https://codereview.chromium.org/1576033002 .
Diffstat (limited to 'fpdfsdk/src/fpdfview.cpp')
-rw-r--r--fpdfsdk/src/fpdfview.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index e047b50846..a6c14206ce 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -1049,11 +1049,15 @@ DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
return 0;
CPDF_NameTree nameTree(pDoc, "Dests");
- int count = nameTree.GetCount();
+ pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount();
CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
if (pDest)
count += pDest->GetCount();
- return count;
+
+ if (!count.IsValid())
+ return 0;
+
+ return count.ValueOrDie();
}
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
@@ -1141,21 +1145,25 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
if (!pRoot)
return nullptr;
- CPDF_Object* pDestObj = NULL;
+ CPDF_Object* pDestObj = nullptr;
CFX_ByteString bsName;
CPDF_NameTree nameTree(pDoc, "Dests");
int count = nameTree.GetCount();
if (index >= count) {
CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
if (!pDest)
- return NULL;
- if (index >= count + pDest->GetCount())
- return NULL;
+ return nullptr;
+
+ pdfium::base::CheckedNumeric<int> checked_count = count;
+ checked_count += pDest->GetCount();
+ if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
+ return nullptr;
+
index -= count;
- FX_POSITION pos = pDest->GetStartPos();
int i = 0;
- while (pos) {
- pDestObj = pDest->GetNextElement(pos, bsName);
+ for (const auto& it : *pDest) {
+ bsName = it.first;
+ pDestObj = it.second;
if (!pDestObj)
continue;
if (i == index)