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

Side by Side Diff: core/fpdfapi/page/cpdf_streamparser.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « core/fpdfapi/page/cpdf_streamcontentparser.cpp ('k') | core/fpdfapi/parser/cfdf_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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfapi/page/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
11 #include <utility>
12
11 #include "core/fpdfapi/cpdf_modulemgr.h" 13 #include "core/fpdfapi/cpdf_modulemgr.h"
12 #include "core/fpdfapi/page/cpdf_docpagedata.h" 14 #include "core/fpdfapi/page/cpdf_docpagedata.h"
13 #include "core/fpdfapi/parser/cpdf_array.h" 15 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_boolean.h" 16 #include "core/fpdfapi/parser/cpdf_boolean.h"
15 #include "core/fpdfapi/parser/cpdf_dictionary.h" 17 #include "core/fpdfapi/parser/cpdf_dictionary.h"
16 #include "core/fpdfapi/parser/cpdf_document.h" 18 #include "core/fpdfapi/parser/cpdf_document.h"
17 #include "core/fpdfapi/parser/cpdf_name.h" 19 #include "core/fpdfapi/parser/cpdf_name.h"
18 #include "core/fpdfapi/parser/cpdf_null.h" 20 #include "core/fpdfapi/parser/cpdf_null.h"
19 #include "core/fpdfapi/parser/cpdf_number.h" 21 #include "core/fpdfapi/parser/cpdf_number.h"
20 #include "core/fpdfapi/parser/cpdf_stream.h" 22 #include "core/fpdfapi/parser/cpdf_stream.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 m_Pos = dwPrevPos; 225 m_Pos = dwPrevPos;
224 break; 226 break;
225 } 227 }
226 dwStreamSize += m_Pos - dwPrevPos; 228 dwStreamSize += m_Pos - dwPrevPos;
227 } 229 }
228 m_Pos = dwSavePos; 230 m_Pos = dwSavePos;
229 pData = FX_Alloc(uint8_t, dwStreamSize); 231 pData = FX_Alloc(uint8_t, dwStreamSize);
230 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize); 232 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
231 m_Pos += dwStreamSize; 233 m_Pos += dwStreamSize;
232 } 234 }
233 pDict->SetIntegerFor("Length", (int)dwStreamSize); 235 pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
234 return new CPDF_Stream(pData, dwStreamSize, pDict); 236 return new CPDF_Stream(pData, dwStreamSize, pDict);
235 } 237 }
236 238
237 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { 239 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() {
238 delete m_pLastObj; 240 delete m_pLastObj;
239 m_pLastObj = nullptr; 241 m_pLastObj = nullptr;
240 242
241 m_WordSize = 0; 243 m_WordSize = 0;
242 bool bIsNumber = true; 244 bool bIsNumber = true;
243 if (!PositionIsInBounds()) 245 if (!PositionIsInBounds())
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (m_WordSize == 2 && m_WordBuffer[0] == '>') 356 if (m_WordSize == 2 && m_WordBuffer[0] == '>')
355 break; 357 break;
356 358
357 if (!m_WordSize || m_WordBuffer[0] != '/') { 359 if (!m_WordSize || m_WordBuffer[0] != '/') {
358 delete pDict; 360 delete pDict;
359 return nullptr; 361 return nullptr;
360 } 362 }
361 363
362 CFX_ByteString key = 364 CFX_ByteString key =
363 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); 365 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1));
364 CPDF_Object* pObj = ReadNextObject(true, 0); 366 auto pObj = pdfium::WrapUnique(ReadNextObject(true, 0));
365 if (!pObj) { 367 if (!pObj) {
366 delete pDict; 368 delete pDict;
367 return nullptr; 369 return nullptr;
368 } 370 }
369 371 if (!key.IsEmpty())
370 if (key.IsEmpty()) 372 pDict->SetFor(key, std::move(pObj));
371 delete pObj;
372 else
373 pDict->SetFor(key, pObj);
374 } 373 }
375 return pDict; 374 return pDict;
376 } 375 }
377 376
378 if (first_char == '[') { 377 if (first_char == '[') {
379 if ((!bAllowNestedArray && dwInArrayLevel) || 378 if ((!bAllowNestedArray && dwInArrayLevel) ||
380 dwInArrayLevel > kMaxNestedArrayLevel) { 379 dwInArrayLevel > kMaxNestedArrayLevel) {
381 return nullptr; 380 return nullptr;
382 } 381 }
383 382
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 616
618 if (buf.GetLength() > kMaxStringLength) 617 if (buf.GetLength() > kMaxStringLength)
619 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); 618 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
620 619
621 return buf.MakeString(); 620 return buf.MakeString();
622 } 621 }
623 622
624 bool CPDF_StreamParser::PositionIsInBounds() const { 623 bool CPDF_StreamParser::PositionIsInBounds() const {
625 return m_Pos < m_Size; 624 return m_Pos < m_Size;
626 } 625 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_streamcontentparser.cpp ('k') | core/fpdfapi/parser/cfdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698