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

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

Issue 1840483003: Reduce signed/unsigned comparison warnings (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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 6
7 #include "core/fxcodec/jbig2/JBig2_Context.h" 7 #include "core/fxcodec/jbig2/JBig2_Context.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 } 1270 }
1271 return JBIG2_SUCCESS; 1271 return JBIG2_SUCCESS;
1272 } 1272 }
1273 1273
1274 JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( 1274 JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable(
1275 CJBig2_BitStream* pStream, 1275 CJBig2_BitStream* pStream,
1276 FX_DWORD SBNUMSYMS) { 1276 FX_DWORD SBNUMSYMS) {
1277 const size_t kRunCodesSize = 35; 1277 const size_t kRunCodesSize = 35;
1278 int32_t runcodes[kRunCodesSize]; 1278 int32_t runcodes[kRunCodesSize];
1279 int32_t runcodes_len[kRunCodesSize]; 1279 int32_t runcodes_len[kRunCodesSize];
1280 for (int32_t i = 0; i < kRunCodesSize; ++i) { 1280 for (size_t i = 0; i < kRunCodesSize; ++i) {
1281 if (pStream->readNBits(4, &runcodes_len[i]) != 0) 1281 if (pStream->readNBits(4, &runcodes_len[i]) != 0)
1282 return nullptr; 1282 return nullptr;
1283 } 1283 }
1284 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); 1284 huffman_assign_code(runcodes, runcodes_len, kRunCodesSize);
1285 1285
1286 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( 1286 std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES(
1287 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); 1287 FX_Alloc(JBig2HuffmanCode, SBNUMSYMS));
1288 int32_t run; 1288 int32_t run;
1289 int32_t i = 0; 1289 int32_t i = 0;
1290 while (i < (int)SBNUMSYMS) { 1290 while (i < (int)SBNUMSYMS) {
1291 int32_t j; 1291 size_t j;
1292 int32_t nVal = 0; 1292 int32_t nVal = 0;
1293 int32_t nBits = 0; 1293 int32_t nBits = 0;
1294 FX_DWORD nTemp; 1294 FX_DWORD nTemp;
1295 while (true) { 1295 while (true) {
1296 if (pStream->read1Bit(&nTemp) != 0) 1296 if (pStream->read1Bit(&nTemp) != 0)
1297 return nullptr; 1297 return nullptr;
1298 1298
1299 nVal = (nVal << 1) | nTemp; 1299 nVal = (nVal << 1) | nTemp;
1300 ++nBits; 1300 ++nBits;
1301 for (j = 0; j < kRunCodesSize; ++j) { 1301 for (j = 0; j < kRunCodesSize; ++j) {
1302 if (nBits == runcodes_len[j] && nVal == runcodes[j]) { 1302 if (nBits == runcodes_len[j] && nVal == runcodes[j]) {
Tom Sepez 2016/03/25 22:31:40 nit: no inner {}
Wei Li 2016/03/26 01:04:10 Done.
1303 break; 1303 break;
1304 } 1304 }
1305 } 1305 }
1306 if (j < kRunCodesSize) { 1306 if (j < kRunCodesSize) {
Tom Sepez 2016/03/25 22:31:40 nit: no {} needed.
Wei Li 2016/03/26 01:04:10 Done.
1307 break; 1307 break;
1308 } 1308 }
1309 } 1309 }
1310 int32_t runcode = j; 1310 int32_t runcode = j;
Tom Sepez 2016/03/25 22:31:40 This may require a cast to avoid a truncation warn
Wei Li 2016/03/26 01:04:10 Done.
1311 if (runcode < 32) { 1311 if (runcode < 32) {
1312 SBSYMCODES.get()[i].codelen = runcode; 1312 SBSYMCODES.get()[i].codelen = runcode;
1313 run = 0; 1313 run = 0;
1314 } else if (runcode == 32) { 1314 } else if (runcode == 32) {
1315 if (pStream->readNBits(2, &nTemp) != 0) 1315 if (pStream->readNBits(2, &nTemp) != 0)
1316 return nullptr; 1316 return nullptr;
1317 run = nTemp + 3; 1317 run = nTemp + 3;
1318 } else if (runcode == 33) { 1318 } else if (runcode == 33) {
1319 if (pStream->readNBits(3, &nTemp) != 0) 1319 if (pStream->readNBits(3, &nTemp) != 0)
1320 return nullptr; 1320 return nullptr;
1321 run = nTemp + 3; 1321 run = nTemp + 3;
1322 } else if (runcode == 34) { 1322 } else if (runcode == 34) {
1323 if (pStream->readNBits(7, &nTemp) != 0) 1323 if (pStream->readNBits(7, &nTemp) != 0)
1324 return nullptr; 1324 return nullptr;
1325 run = nTemp + 11; 1325 run = nTemp + 11;
1326 } 1326 }
1327 if (run > 0) { 1327 if (run > 0) {
1328 if (i + run > (int)SBNUMSYMS) 1328 if (i + run > (int)SBNUMSYMS)
1329 return nullptr; 1329 return nullptr;
1330 for (j = 0; j < run; ++j) { 1330 for (int32_t k = 0; k < run; ++k) {
1331 if (runcode == 32 && i > 0) { 1331 if (runcode == 32 && i > 0) {
1332 SBSYMCODES.get()[i + j].codelen = SBSYMCODES.get()[i - 1].codelen; 1332 SBSYMCODES.get()[i + k].codelen = SBSYMCODES.get()[i - 1].codelen;
1333 } else { 1333 } else {
1334 SBSYMCODES.get()[i + j].codelen = 0; 1334 SBSYMCODES.get()[i + k].codelen = 0;
1335 } 1335 }
1336 } 1336 }
1337 i += run; 1337 i += run;
1338 } else { 1338 } else {
1339 ++i; 1339 ++i;
1340 } 1340 }
1341 } 1341 }
1342 huffman_assign_code(SBSYMCODES.get(), SBNUMSYMS); 1342 huffman_assign_code(SBSYMCODES.get(), SBNUMSYMS);
1343 return SBSYMCODES.release(); 1343 return SBSYMCODES.release();
1344 } 1344 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 SBSYMCODES[CURTEMP].code = CURCODE; 1408 SBSYMCODES[CURTEMP].code = CURCODE;
1409 CURCODE = CURCODE + 1; 1409 CURCODE = CURCODE + 1;
1410 } 1410 }
1411 CURTEMP = CURTEMP + 1; 1411 CURTEMP = CURTEMP + 1;
1412 } 1412 }
1413 CURLEN = CURLEN + 1; 1413 CURLEN = CURLEN + 1;
1414 } 1414 }
1415 FX_Free(LENCOUNT); 1415 FX_Free(LENCOUNT);
1416 FX_Free(FIRSTCODE); 1416 FX_Free(FIRSTCODE);
1417 } 1417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698