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

Side by Side Diff: core/fpdfapi/parser/cpdf_syntax_parser.cpp

Issue 2584683002: Return unique_ptr from CFX_BinaryBuf::DetachBuffer() (Closed)
Patch Set: Created 4 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
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | core/fxcrt/fx_basic.h » ('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/parser/cpdf_syntax_parser.h" 7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 if (len < 0) 716 if (len < 0)
717 return nullptr; 717 return nullptr;
718 718
719 pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(len)); 719 pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(len));
720 } 720 }
721 m_Pos = streamStartPos; 721 m_Pos = streamStartPos;
722 } 722 }
723 if (len < 0) 723 if (len < 0)
724 return nullptr; 724 return nullptr;
725 725
726 uint8_t* pData = nullptr; 726 std::unique_ptr<uint8_t, FxFreeDeleter> pData;
727 if (len > 0) { 727 if (len > 0) {
728 pData = FX_Alloc(uint8_t, len); 728 pData.reset(FX_Alloc(uint8_t, len));
729 ReadBlock(pData, len); 729 ReadBlock(pData.get(), len);
730 if (pCryptoHandler) { 730 if (pCryptoHandler) {
731 CFX_BinaryBuf dest_buf; 731 CFX_BinaryBuf dest_buf;
732 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); 732 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len));
733 733
734 void* context = pCryptoHandler->DecryptStart(objnum, gennum); 734 void* context = pCryptoHandler->DecryptStart(objnum, gennum);
735 pCryptoHandler->DecryptStream(context, pData, len, dest_buf); 735 pCryptoHandler->DecryptStream(context, pData.get(), len, dest_buf);
736 pCryptoHandler->DecryptFinish(context, dest_buf); 736 pCryptoHandler->DecryptFinish(context, dest_buf);
737 FX_Free(pData);
738 pData = dest_buf.GetBuffer();
739 len = dest_buf.GetSize(); 737 len = dest_buf.GetSize();
740 dest_buf.DetachBuffer(); 738 pData = dest_buf.DetachBuffer();
741 } 739 }
742 } 740 }
743 741
744 auto pStream = pdfium::MakeUnique<CPDF_Stream>(pData, len, std::move(pDict)); 742 auto pStream =
743 pdfium::MakeUnique<CPDF_Stream>(std::move(pData), len, std::move(pDict));
745 streamStartPos = m_Pos; 744 streamStartPos = m_Pos;
746 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); 745 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1);
747 GetNextWordInternal(nullptr); 746 GetNextWordInternal(nullptr);
748 747
749 int numMarkers = ReadEOLMarkers(m_Pos); 748 int numMarkers = ReadEOLMarkers(m_Pos);
750 if (m_WordSize == static_cast<unsigned int>(kEndObjStr.GetLength()) && 749 if (m_WordSize == static_cast<unsigned int>(kEndObjStr.GetLength()) &&
751 numMarkers != 0 && 750 numMarkers != 0 &&
752 FXSYS_memcmp(m_WordBuffer, kEndObjStr.raw_str(), 751 FXSYS_memcmp(m_WordBuffer, kEndObjStr.raw_str(),
753 kEndObjStr.GetLength()) == 0) { 752 kEndObjStr.GetLength()) == 0) {
754 m_Pos = streamStartPos; 753 m_Pos = streamStartPos;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 if (limit && m_Pos == limit) 901 if (limit && m_Pos == limit)
903 return -1; 902 return -1;
904 } 903 }
905 return -1; 904 return -1;
906 } 905 }
907 906
908 void CPDF_SyntaxParser::SetEncrypt( 907 void CPDF_SyntaxParser::SetEncrypt(
909 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { 908 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) {
910 m_pCryptoHandler = std::move(pCryptoHandler); 909 m_pCryptoHandler = std::move(pCryptoHandler);
911 } 910 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_stream.cpp ('k') | core/fxcrt/fx_basic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698