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

Side by Side Diff: core/fxcodec/jbig2/JBig2_SddProc.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase 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/fxcodec/jbig2/JBig2_HtrdProc.cpp ('k') | core/fxcodec/jbig2/JBig2_TrdProc.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 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 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/fxcodec/jbig2/JBig2_SddProc.h" 7 #include "core/fxcodec/jbig2/JBig2_SddProc.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "core/fxcodec/jbig2/JBig2_ArithIntDecoder.h" 12 #include "core/fxcodec/jbig2/JBig2_ArithIntDecoder.h"
13 #include "core/fxcodec/jbig2/JBig2_GrdProc.h" 13 #include "core/fxcodec/jbig2/JBig2_GrdProc.h"
14 #include "core/fxcodec/jbig2/JBig2_GrrdProc.h" 14 #include "core/fxcodec/jbig2/JBig2_GrrdProc.h"
15 #include "core/fxcodec/jbig2/JBig2_HuffmanDecoder.h" 15 #include "core/fxcodec/jbig2/JBig2_HuffmanDecoder.h"
16 #include "core/fxcodec/jbig2/JBig2_HuffmanTable.h" 16 #include "core/fxcodec/jbig2/JBig2_HuffmanTable.h"
17 #include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h" 17 #include "core/fxcodec/jbig2/JBig2_HuffmanTable_Standard.h"
18 #include "core/fxcodec/jbig2/JBig2_SymbolDict.h" 18 #include "core/fxcodec/jbig2/JBig2_SymbolDict.h"
19 #include "core/fxcodec/jbig2/JBig2_TrdProc.h" 19 #include "core/fxcodec/jbig2/JBig2_TrdProc.h"
20 #include "core/fxcrt/fx_basic.h" 20 #include "core/fxcrt/fx_basic.h"
21 #include "third_party/base/ptr_util.h"
21 22
22 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( 23 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith(
23 CJBig2_ArithDecoder* pArithDecoder, 24 CJBig2_ArithDecoder* pArithDecoder,
24 std::vector<JBig2ArithCtx>* gbContext, 25 std::vector<JBig2ArithCtx>* gbContext,
25 std::vector<JBig2ArithCtx>* grContext) { 26 std::vector<JBig2ArithCtx>* grContext) {
26 CJBig2_Image** SDNEWSYMS; 27 CJBig2_Image** SDNEWSYMS;
27 uint32_t HCHEIGHT, NSYMSDECODED; 28 uint32_t HCHEIGHT, NSYMSDECODED;
28 int32_t HCDH; 29 int32_t HCDH;
29 uint32_t SYMWIDTH, TOTWIDTH; 30 uint32_t SYMWIDTH, TOTWIDTH;
30 int32_t DW; 31 int32_t DW;
(...skipping 21 matching lines...) Expand all
52 std::unique_ptr<CJBig2_ArithIntDecoder> IAFS(new CJBig2_ArithIntDecoder); 53 std::unique_ptr<CJBig2_ArithIntDecoder> IAFS(new CJBig2_ArithIntDecoder);
53 std::unique_ptr<CJBig2_ArithIntDecoder> IADS(new CJBig2_ArithIntDecoder); 54 std::unique_ptr<CJBig2_ArithIntDecoder> IADS(new CJBig2_ArithIntDecoder);
54 std::unique_ptr<CJBig2_ArithIntDecoder> IAIT(new CJBig2_ArithIntDecoder); 55 std::unique_ptr<CJBig2_ArithIntDecoder> IAIT(new CJBig2_ArithIntDecoder);
55 std::unique_ptr<CJBig2_ArithIntDecoder> IARI(new CJBig2_ArithIntDecoder); 56 std::unique_ptr<CJBig2_ArithIntDecoder> IARI(new CJBig2_ArithIntDecoder);
56 std::unique_ptr<CJBig2_ArithIntDecoder> IARDW(new CJBig2_ArithIntDecoder); 57 std::unique_ptr<CJBig2_ArithIntDecoder> IARDW(new CJBig2_ArithIntDecoder);
57 std::unique_ptr<CJBig2_ArithIntDecoder> IARDH(new CJBig2_ArithIntDecoder); 58 std::unique_ptr<CJBig2_ArithIntDecoder> IARDH(new CJBig2_ArithIntDecoder);
58 nTmp = 0; 59 nTmp = 0;
59 while ((uint32_t)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) { 60 while ((uint32_t)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) {
60 nTmp++; 61 nTmp++;
61 } 62 }
62 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp)); 63 IAID = pdfium::MakeUnique<CJBig2_ArithIaidDecoder>((uint8_t)nTmp);
63 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); 64 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS);
64 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); 65 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*));
65 66
66 HCHEIGHT = 0; 67 HCHEIGHT = 0;
67 NSYMSDECODED = 0; 68 NSYMSDECODED = 0;
68 while (NSYMSDECODED < SDNUMNEWSYMS) { 69 while (NSYMSDECODED < SDNUMNEWSYMS) {
69 BS = nullptr; 70 BS = nullptr;
70 IADH->decode(pArithDecoder, &HCDH); 71 IADH->decode(pArithDecoder, &HCDH);
71 HCHEIGHT = HCHEIGHT + HCDH; 72 HCHEIGHT = HCHEIGHT + HCDH;
72 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { 73 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 252 }
252 } 253 }
253 EXINDEX = EXINDEX + EXRUNLENGTH; 254 EXINDEX = EXINDEX + EXRUNLENGTH;
254 CUREXFLAG = !CUREXFLAG; 255 CUREXFLAG = !CUREXFLAG;
255 } 256 }
256 if (num_ex_syms > SDNUMEXSYMS) { 257 if (num_ex_syms > SDNUMEXSYMS) {
257 FX_Free(EXFLAGS); 258 FX_Free(EXFLAGS);
258 goto failed; 259 goto failed;
259 } 260 }
260 261
261 pDict.reset(new CJBig2_SymbolDict); 262 pDict = pdfium::MakeUnique<CJBig2_SymbolDict>();
262 I = J = 0; 263 I = J = 0;
263 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { 264 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) {
264 if (EXFLAGS[I] && J < SDNUMEXSYMS) { 265 if (EXFLAGS[I] && J < SDNUMEXSYMS) {
265 if (I < SDNUMINSYMS) { 266 if (I < SDNUMINSYMS) {
266 pDict->AddImage(SDINSYMS[I] ? new CJBig2_Image(*SDINSYMS[I]) : nullptr); 267 pDict->AddImage(SDINSYMS[I] ? new CJBig2_Image(*SDINSYMS[I]) : nullptr);
267 } else { 268 } else {
268 pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]); 269 pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]);
269 } 270 }
270 ++J; 271 ++J;
271 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { 272 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) { 556 for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) {
556 SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT); 557 SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT);
557 nTmp += SDNEWSYMWIDTHS[I]; 558 nTmp += SDNEWSYMWIDTHS[I];
558 } 559 }
559 delete BHC; 560 delete BHC;
560 BHC = nullptr; 561 BHC = nullptr;
561 } 562 }
562 } 563 }
563 EXINDEX = 0; 564 EXINDEX = 0;
564 CUREXFLAG = 0; 565 CUREXFLAG = 0;
565 pTable.reset(new CJBig2_HuffmanTable(HuffmanTable_B1, HuffmanTable_B1_Size, 566 pTable = pdfium::MakeUnique<CJBig2_HuffmanTable>(
566 HuffmanTable_HTOOB_B1)); 567 HuffmanTable_B1, HuffmanTable_B1_Size, HuffmanTable_HTOOB_B1);
567 EXFLAGS = FX_Alloc(bool, SDNUMINSYMS + SDNUMNEWSYMS); 568 EXFLAGS = FX_Alloc(bool, SDNUMINSYMS + SDNUMNEWSYMS);
568 num_ex_syms = 0; 569 num_ex_syms = 0;
569 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { 570 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) {
570 if (pHuffmanDecoder->decodeAValue(pTable.get(), (int*)&EXRUNLENGTH) != 0) { 571 if (pHuffmanDecoder->decodeAValue(pTable.get(), (int*)&EXRUNLENGTH) != 0) {
571 FX_Free(EXFLAGS); 572 FX_Free(EXFLAGS);
572 goto failed; 573 goto failed;
573 } 574 }
574 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { 575 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) {
575 FX_Free(EXFLAGS); 576 FX_Free(EXFLAGS);
576 goto failed; 577 goto failed;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 failed: 614 failed:
614 for (I = 0; I < NSYMSDECODED; I++) { 615 for (I = 0; I < NSYMSDECODED; I++) {
615 delete SDNEWSYMS[I]; 616 delete SDNEWSYMS[I];
616 } 617 }
617 FX_Free(SDNEWSYMS); 618 FX_Free(SDNEWSYMS);
618 if (SDREFAGG == 0) { 619 if (SDREFAGG == 0) {
619 FX_Free(SDNEWSYMWIDTHS); 620 FX_Free(SDNEWSYMWIDTHS);
620 } 621 }
621 return nullptr; 622 return nullptr;
622 } 623 }
OLDNEW
« no previous file with comments | « core/fxcodec/jbig2/JBig2_HtrdProc.cpp ('k') | core/fxcodec/jbig2/JBig2_TrdProc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698