Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1541703003: Use std::map as CPDF_Dictionary's underlying store. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments, rebase, fix embedder test Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdfppo.cpp ('k') | fpdfsdk/src/javascript/Document.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "public/fpdfview.h" 7 #include "public/fpdfview.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { 820 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
821 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 821 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
822 if (!pDoc) 822 if (!pDoc)
823 return 0; 823 return 0;
824 824
825 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 825 CPDF_Dictionary* pRoot = pDoc->GetRoot();
826 if (!pRoot) 826 if (!pRoot)
827 return 0; 827 return 0;
828 828
829 CPDF_NameTree nameTree(pDoc, "Dests"); 829 CPDF_NameTree nameTree(pDoc, "Dests");
830 int count = nameTree.GetCount(); 830 pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount();
831 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); 831 CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
832 if (pDest) 832 if (pDest)
833 count += pDest->GetCount(); 833 count += pDest->GetCount();
834 return count; 834
835 if (!count.IsValid())
836 return 0;
837
838 return count.ValueOrDie();
835 } 839 }
836 840
837 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, 841 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
838 FPDF_BYTESTRING name) { 842 FPDF_BYTESTRING name) {
839 if (!name || name[0] == 0) 843 if (!name || name[0] == 0)
840 return nullptr; 844 return nullptr;
841 845
842 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 846 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
843 if (!pDoc) 847 if (!pDoc)
844 return nullptr; 848 return nullptr;
(...skipping 13 matching lines...) Expand all
858 return nullptr; 862 return nullptr;
859 863
860 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 864 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
861 if (!pDoc) 865 if (!pDoc)
862 return nullptr; 866 return nullptr;
863 867
864 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 868 CPDF_Dictionary* pRoot = pDoc->GetRoot();
865 if (!pRoot) 869 if (!pRoot)
866 return nullptr; 870 return nullptr;
867 871
868 CPDF_Object* pDestObj = NULL; 872 CPDF_Object* pDestObj = nullptr;
869 CFX_ByteString bsName; 873 CFX_ByteString bsName;
870 CPDF_NameTree nameTree(pDoc, "Dests"); 874 CPDF_NameTree nameTree(pDoc, "Dests");
871 int count = nameTree.GetCount(); 875 int count = nameTree.GetCount();
872 if (index >= count) { 876 if (index >= count) {
873 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); 877 CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
874 if (!pDest) 878 if (!pDest)
875 return NULL; 879 return nullptr;
876 if (index >= count + pDest->GetCount()) 880
877 return NULL; 881 pdfium::base::CheckedNumeric<int> checked_count = count;
882 checked_count += pDest->GetCount();
883 if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
884 return nullptr;
885
878 index -= count; 886 index -= count;
879 FX_POSITION pos = pDest->GetStartPos();
880 int i = 0; 887 int i = 0;
881 while (pos) { 888 for (const auto& it : *pDest) {
882 pDestObj = pDest->GetNextElement(pos, bsName); 889 bsName = it.first;
890 pDestObj = it.second;
883 if (!pDestObj) 891 if (!pDestObj)
884 continue; 892 continue;
885 if (i == index) 893 if (i == index)
886 break; 894 break;
887 i++; 895 i++;
888 } 896 }
889 } else { 897 } else {
890 pDestObj = nameTree.LookupValue(index, bsName); 898 pDestObj = nameTree.LookupValue(index, bsName);
891 } 899 }
892 if (!pDestObj) 900 if (!pDestObj)
(...skipping 12 matching lines...) Expand all
905 if (!buffer) { 913 if (!buffer) {
906 *buflen = len; 914 *buflen = len;
907 } else if (*buflen >= len) { 915 } else if (*buflen >= len) {
908 memcpy(buffer, utf16Name.c_str(), len); 916 memcpy(buffer, utf16Name.c_str(), len);
909 *buflen = len; 917 *buflen = len;
910 } else { 918 } else {
911 *buflen = -1; 919 *buflen = -1;
912 } 920 }
913 return (FPDF_DEST)pDestObj; 921 return (FPDF_DEST)pDestObj;
914 } 922 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfppo.cpp ('k') | fpdfsdk/src/javascript/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698