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

Side by Side Diff: xfa/src/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp

Issue 1726373002: Remove foo != NULL checks in xfa/src/fxbarcode. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 10 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
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 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2007 ZXing authors 8 * Copyright 2007 ZXing authors
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
(...skipping 22 matching lines...) Expand all
33 m_tempBitMatrix = bitMatrix; 33 m_tempBitMatrix = bitMatrix;
34 if (m_dimension < 21 || (m_dimension & 0x03) != 1) { 34 if (m_dimension < 21 || (m_dimension & 0x03) != 1) {
35 e = BCExceptionRead; 35 e = BCExceptionRead;
36 BC_EXCEPTION_CHECK_ReturnVoid(e); 36 BC_EXCEPTION_CHECK_ReturnVoid(e);
37 } 37 }
38 m_bitMatrix = m_tempBitMatrix; 38 m_bitMatrix = m_tempBitMatrix;
39 m_parsedFormatInfo = NULL; 39 m_parsedFormatInfo = NULL;
40 m_version = NULL; 40 m_version = NULL;
41 } 41 }
42 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() { 42 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() {
43 if (m_parsedFormatInfo != NULL) { 43 delete m_parsedFormatInfo;
44 delete m_parsedFormatInfo;
45 m_parsedFormatInfo = NULL;
46 }
47 m_version = NULL;
48 } 44 }
49 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation( 45 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation(
50 int32_t& e) { 46 int32_t& e) {
51 if (m_parsedFormatInfo != NULL) { 47 if (m_parsedFormatInfo) {
52 return m_parsedFormatInfo; 48 return m_parsedFormatInfo;
53 } 49 }
54 int32_t formatInfoBits = 0; 50 int32_t formatInfoBits = 0;
55 int32_t j; 51 int32_t j;
56 for (j = 0; j < 6; j++) { 52 for (j = 0; j < 6; j++) {
57 formatInfoBits = CopyBit(8, j, formatInfoBits); 53 formatInfoBits = CopyBit(8, j, formatInfoBits);
58 } 54 }
59 formatInfoBits = CopyBit(8, 7, formatInfoBits); 55 formatInfoBits = CopyBit(8, 7, formatInfoBits);
60 formatInfoBits = CopyBit(8, 8, formatInfoBits); 56 formatInfoBits = CopyBit(8, 8, formatInfoBits);
61 formatInfoBits = CopyBit(7, 8, formatInfoBits); 57 formatInfoBits = CopyBit(7, 8, formatInfoBits);
62 for (int32_t i = 5; i >= 0; i--) { 58 for (int32_t i = 5; i >= 0; i--) {
63 formatInfoBits = CopyBit(i, 8, formatInfoBits); 59 formatInfoBits = CopyBit(i, 8, formatInfoBits);
64 } 60 }
65 m_parsedFormatInfo = 61 m_parsedFormatInfo =
66 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); 62 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits);
67 if (m_parsedFormatInfo != NULL) { 63 if (m_parsedFormatInfo) {
68 return m_parsedFormatInfo; 64 return m_parsedFormatInfo;
69 } 65 }
70 int32_t dimension = m_bitMatrix->GetDimension(e); 66 int32_t dimension = m_bitMatrix->GetDimension(e);
71 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 67 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
72 formatInfoBits = 0; 68 formatInfoBits = 0;
73 int32_t iMin = dimension - 8; 69 int32_t iMin = dimension - 8;
74 for (j = dimension - 1; j >= iMin; j--) { 70 for (j = dimension - 1; j >= iMin; j--) {
75 formatInfoBits = CopyBit(j, 8, formatInfoBits); 71 formatInfoBits = CopyBit(j, 8, formatInfoBits);
76 } 72 }
77 for (int32_t k = dimension - 7; k < dimension; k++) { 73 for (int32_t k = dimension - 7; k < dimension; k++) {
78 formatInfoBits = CopyBit(8, k, formatInfoBits); 74 formatInfoBits = CopyBit(8, k, formatInfoBits);
79 } 75 }
80 m_parsedFormatInfo = 76 m_parsedFormatInfo =
81 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); 77 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits);
82 if (m_parsedFormatInfo != NULL) { 78 if (m_parsedFormatInfo) {
83 return m_parsedFormatInfo; 79 return m_parsedFormatInfo;
84 } 80 }
85 e = BCExceptionRead; 81 e = BCExceptionRead;
86 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 82 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
87 return NULL; 83 return NULL;
88 } 84 }
89 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) { 85 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) {
90 if (m_version != NULL) { 86 if (m_version) {
91 return m_version; 87 return m_version;
92 } 88 }
93 int32_t dimension = m_bitMatrix->GetDimension(e); 89 int32_t dimension = m_bitMatrix->GetDimension(e);
94 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 90 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
95 int32_t provisionVersion = (dimension - 17) >> 2; 91 int32_t provisionVersion = (dimension - 17) >> 2;
96 if (provisionVersion <= 6) { 92 if (provisionVersion <= 6) {
97 CBC_QRCoderVersion* qrv = 93 CBC_QRCoderVersion* qrv =
98 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e); 94 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e);
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 95 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
100 return qrv; 96 return qrv;
101 } 97 }
102 int32_t versionBits = 0; 98 int32_t versionBits = 0;
103 for (int32_t i = 5; i >= 0; i--) { 99 for (int32_t i = 5; i >= 0; i--) {
104 int32_t jMin = dimension - 11; 100 int32_t jMin = dimension - 11;
105 for (int32_t j = dimension - 9; j >= jMin; j--) { 101 for (int32_t j = dimension - 9; j >= jMin; j--) {
106 versionBits = CopyBit(i, j, versionBits); 102 versionBits = CopyBit(i, j, versionBits);
107 } 103 }
108 } 104 }
109 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); 105 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e);
110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 106 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
111 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { 107 if (m_version && m_version->GetDimensionForVersion() == dimension) {
112 return m_version; 108 return m_version;
113 } 109 }
114 versionBits = 0; 110 versionBits = 0;
115 for (int32_t j = 5; j >= 0; j--) { 111 for (int32_t j = 5; j >= 0; j--) {
116 int32_t iMin = dimension - 11; 112 int32_t iMin = dimension - 11;
117 for (int32_t i = dimension - 9; i >= iMin; i--) { 113 for (int32_t i = dimension - 9; i >= iMin; i--) {
118 versionBits = CopyBit(i, j, versionBits); 114 versionBits = CopyBit(i, j, versionBits);
119 } 115 }
120 } 116 }
121 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); 117 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e);
122 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 118 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
123 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { 119 if (m_version && m_version->GetDimensionForVersion() == dimension) {
124 return m_version; 120 return m_version;
125 } 121 }
126 e = BCExceptionRead; 122 e = BCExceptionRead;
127 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 123 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
128 return NULL; 124 return NULL;
129 } 125 }
130 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, 126 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i,
131 int32_t j, 127 int32_t j,
132 int32_t versionBits) { 128 int32_t versionBits) {
133 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; 129 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 171 }
176 } 172 }
177 readingUp ^= TRUE; 173 readingUp ^= TRUE;
178 } 174 }
179 if (resultOffset != version->GetTotalCodeWords()) { 175 if (resultOffset != version->GetTotalCodeWords()) {
180 e = BCExceptionRead; 176 e = BCExceptionRead;
181 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 177 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
182 } 178 }
183 return result.release(); 179 return result.release();
184 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698