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

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: XFA still uses CFX_CMapByteStringToPtr :( Created 5 years 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
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 "core/include/fxcodec/fx_codec.h" 9 #include "core/include/fxcodec/fx_codec.h"
10 #include "core/include/fxcrt/fx_safe_types.h" 10 #include "core/include/fxcrt/fx_safe_types.h"
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { 818 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
819 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 819 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
820 if (!pDoc) 820 if (!pDoc)
821 return 0; 821 return 0;
822 822
823 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 823 CPDF_Dictionary* pRoot = pDoc->GetRoot();
824 if (!pRoot) 824 if (!pRoot)
825 return 0; 825 return 0;
826 826
827 CPDF_NameTree nameTree(pDoc, "Dests"); 827 CPDF_NameTree nameTree(pDoc, "Dests");
828 int count = nameTree.GetCount(); 828 pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount();
829 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); 829 CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
830 if (pDest) 830 if (pDest)
831 count += pDest->GetCount(); 831 count += pDest->GetCount();
832 return count; 832
833 if (!count.IsValid())
834 return 0;
835
836 return count.ValueOrDie();
833 } 837 }
834 838
835 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, 839 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
836 FPDF_BYTESTRING name) { 840 FPDF_BYTESTRING name) {
837 if (!name || name[0] == 0) 841 if (!name || name[0] == 0)
838 return nullptr; 842 return nullptr;
839 843
840 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 844 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
841 if (!pDoc) 845 if (!pDoc)
842 return nullptr; 846 return nullptr;
(...skipping 13 matching lines...) Expand all
856 return nullptr; 860 return nullptr;
857 861
858 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 862 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
859 if (!pDoc) 863 if (!pDoc)
860 return nullptr; 864 return nullptr;
861 865
862 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 866 CPDF_Dictionary* pRoot = pDoc->GetRoot();
863 if (!pRoot) 867 if (!pRoot)
864 return nullptr; 868 return nullptr;
865 869
866 CPDF_Object* pDestObj = NULL; 870 CPDF_Object* pDestObj = nullptr;
867 CFX_ByteString bsName; 871 CFX_ByteString bsName;
868 CPDF_NameTree nameTree(pDoc, "Dests"); 872 CPDF_NameTree nameTree(pDoc, "Dests");
869 int count = nameTree.GetCount(); 873 int count = nameTree.GetCount();
870 if (index >= count) { 874 if (index >= count) {
871 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); 875 CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
872 if (!pDest) 876 if (!pDest)
873 return NULL; 877 return nullptr;
874 if (index >= count + pDest->GetCount()) 878
875 return NULL; 879 pdfium::base::CheckedNumeric<int> checked_count = count;
880 checked_count += pDest->GetCount();
881 if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
882 return nullptr;
883
876 index -= count; 884 index -= count;
877 FX_POSITION pos = pDest->GetStartPos();
878 int i = 0; 885 int i = 0;
879 while (pos) { 886 for (const auto& it : *pDest) {
880 pDestObj = pDest->GetNextElement(pos, bsName); 887 bsName = it.first;
888 pDestObj = it.second;
881 if (!pDestObj) 889 if (!pDestObj)
882 continue; 890 continue;
883 if (i == index) 891 if (i == index)
884 break; 892 break;
885 i++; 893 i++;
886 } 894 }
887 } else { 895 } else {
888 pDestObj = nameTree.LookupValue(index, bsName); 896 pDestObj = nameTree.LookupValue(index, bsName);
889 } 897 }
890 if (!pDestObj) 898 if (!pDestObj)
(...skipping 12 matching lines...) Expand all
903 if (!buffer) { 911 if (!buffer) {
904 *buflen = len; 912 *buflen = len;
905 } else if (*buflen >= len) { 913 } else if (*buflen >= len) {
906 memcpy(buffer, utf16Name.c_str(), len); 914 memcpy(buffer, utf16Name.c_str(), len);
907 *buflen = len; 915 *buflen = len;
908 } else { 916 } else {
909 *buflen = -1; 917 *buflen = -1;
910 } 918 }
911 return (FPDF_DEST)pDestObj; 919 return (FPDF_DEST)pDestObj;
912 } 920 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698