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

Side by Side Diff: core/src/fxcodec/lbmp/fx_bmp.cpp

Issue 1720043003: Remove foo != NULL outside of xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase 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
« no previous file with comments | « core/src/fxcodec/lbmp/fx_bmp.h ('k') | core/src/fxcodec/lgif/fx_gif.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 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/src/fxcodec/lbmp/fx_bmp.h" 7 #include "core/src/fxcodec/lbmp/fx_bmp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 14 matching lines...) Expand all
25 p[0] = (uint8_t)v; 25 p[0] = (uint8_t)v;
26 p[1] = (uint8_t)(v >> 8); 26 p[1] = (uint8_t)(v >> 8);
27 p[2] = (uint8_t)(v >> 16); 27 p[2] = (uint8_t)(v >> 16);
28 p[3] = (uint8_t)(v >> 24); 28 p[3] = (uint8_t)(v >> 24);
29 } 29 }
30 void _SetWord_LSBFirst(uint8_t* p, FX_WORD v) { 30 void _SetWord_LSBFirst(uint8_t* p, FX_WORD v) {
31 p[0] = (uint8_t)v; 31 p[0] = (uint8_t)v;
32 p[1] = (uint8_t)(v >> 8); 32 p[1] = (uint8_t)(v >> 8);
33 } 33 }
34 void _bmp_error(bmp_decompress_struct_p bmp_ptr, const FX_CHAR* err_msg) { 34 void _bmp_error(bmp_decompress_struct_p bmp_ptr, const FX_CHAR* err_msg) {
35 if (bmp_ptr != NULL && bmp_ptr->_bmp_error_fn != NULL) { 35 if (bmp_ptr && bmp_ptr->_bmp_error_fn) {
36 bmp_ptr->_bmp_error_fn(bmp_ptr, err_msg); 36 bmp_ptr->_bmp_error_fn(bmp_ptr, err_msg);
37 } 37 }
38 } 38 }
39 bmp_decompress_struct_p _bmp_create_decompress() { 39 bmp_decompress_struct_p _bmp_create_decompress() {
40 bmp_decompress_struct_p bmp_ptr = FX_Alloc(bmp_decompress_struct, 1); 40 bmp_decompress_struct_p bmp_ptr = FX_Alloc(bmp_decompress_struct, 1);
41 if (bmp_ptr == NULL) { 41 if (bmp_ptr == NULL) {
42 return NULL; 42 return NULL;
43 } 43 }
44 FXSYS_memset(bmp_ptr, 0, sizeof(bmp_decompress_struct)); 44 FXSYS_memset(bmp_ptr, 0, sizeof(bmp_decompress_struct));
45 bmp_ptr->decode_status = BMP_D_STATUS_HEADER; 45 bmp_ptr->decode_status = BMP_D_STATUS_HEADER;
46 bmp_ptr->bmp_header_ptr = FX_Alloc(BmpFileHeader, 1); 46 bmp_ptr->bmp_header_ptr = FX_Alloc(BmpFileHeader, 1);
47 return bmp_ptr; 47 return bmp_ptr;
48 } 48 }
49 void _bmp_destroy_decompress(bmp_decompress_struct_pp bmp_ptr_ptr) { 49 void _bmp_destroy_decompress(bmp_decompress_struct_pp bmp_ptr_ptr) {
50 if (bmp_ptr_ptr == NULL || *bmp_ptr_ptr == NULL) { 50 if (bmp_ptr_ptr == NULL || *bmp_ptr_ptr == NULL) {
51 return; 51 return;
52 } 52 }
53 bmp_decompress_struct_p bmp_ptr = *bmp_ptr_ptr; 53 bmp_decompress_struct_p bmp_ptr = *bmp_ptr_ptr;
54 *bmp_ptr_ptr = NULL; 54 *bmp_ptr_ptr = NULL;
55 if (bmp_ptr->out_row_buffer != NULL) { 55 if (bmp_ptr->out_row_buffer) {
56 FX_Free(bmp_ptr->out_row_buffer); 56 FX_Free(bmp_ptr->out_row_buffer);
57 } 57 }
58 if (bmp_ptr->pal_ptr != NULL) { 58 FX_Free(bmp_ptr->pal_ptr);
59 FX_Free(bmp_ptr->pal_ptr); 59 FX_Free(bmp_ptr->bmp_header_ptr);
60 }
61 if (bmp_ptr->bmp_header_ptr != NULL) {
62 FX_Free(bmp_ptr->bmp_header_ptr);
63 }
64 FX_Free(bmp_ptr); 60 FX_Free(bmp_ptr);
65 } 61 }
66 int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr) { 62 int32_t _bmp_read_header(bmp_decompress_struct_p bmp_ptr) {
67 if (bmp_ptr == NULL) { 63 if (bmp_ptr == NULL) {
68 return 0; 64 return 0;
69 } 65 }
70 FX_DWORD skip_size_org = bmp_ptr->skip_size; 66 FX_DWORD skip_size_org = bmp_ptr->skip_size;
71 if (bmp_ptr->decode_status == BMP_D_STATUS_HEADER) { 67 if (bmp_ptr->decode_status == BMP_D_STATUS_HEADER) {
72 ASSERT(sizeof(BmpFileHeader) == 14); 68 ASSERT(sizeof(BmpFileHeader) == 14);
73 BmpFileHeader* bmp_header_ptr = NULL; 69 BmpFileHeader* bmp_header_ptr = NULL;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 case 16: 207 case 16:
212 case 24: 208 case 24:
213 bmp_ptr->out_row_bytes = BMP_WIDTHBYTES(bmp_ptr->width, 24); 209 bmp_ptr->out_row_bytes = BMP_WIDTHBYTES(bmp_ptr->width, 24);
214 bmp_ptr->components = 3; 210 bmp_ptr->components = 3;
215 break; 211 break;
216 case 32: 212 case 32:
217 bmp_ptr->out_row_bytes = bmp_ptr->src_row_bytes; 213 bmp_ptr->out_row_bytes = bmp_ptr->src_row_bytes;
218 bmp_ptr->components = 4; 214 bmp_ptr->components = 4;
219 break; 215 break;
220 } 216 }
221 if (bmp_ptr->out_row_buffer != NULL) { 217 FX_Free(bmp_ptr->out_row_buffer);
222 FX_Free(bmp_ptr->out_row_buffer);
223 bmp_ptr->out_row_buffer = NULL;
224 }
225 bmp_ptr->out_row_buffer = FX_Alloc(uint8_t, bmp_ptr->out_row_bytes); 218 bmp_ptr->out_row_buffer = FX_Alloc(uint8_t, bmp_ptr->out_row_bytes);
226 BMP_PTR_NOT_NULL(bmp_ptr->out_row_buffer, bmp_ptr);
227 FXSYS_memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); 219 FXSYS_memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes);
228 _bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_PAL); 220 _bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_PAL);
229 } 221 }
230 if (bmp_ptr->decode_status == BMP_D_STATUS_PAL) { 222 if (bmp_ptr->decode_status == BMP_D_STATUS_PAL) {
231 skip_size_org = bmp_ptr->skip_size; 223 skip_size_org = bmp_ptr->skip_size;
232 #ifdef BMP_SUPPORT_BITFIELD 224 #ifdef BMP_SUPPORT_BITFIELD
233 if (bmp_ptr->compress_flag == BMP_BITFIELDS) { 225 if (bmp_ptr->compress_flag == BMP_BITFIELDS) {
234 if (bmp_ptr->bitCounts != 16 && bmp_ptr->bitCounts != 32) { 226 if (bmp_ptr->bitCounts != 16 && bmp_ptr->bitCounts != 32) {
235 _bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); 227 _bmp_error(bmp_ptr, "The Bmp File Is Corrupt");
236 return 0; 228 return 0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (bmp_ptr->color_used != 0) { 264 if (bmp_ptr->color_used != 0) {
273 bmp_ptr->pal_num = bmp_ptr->color_used; 265 bmp_ptr->pal_num = bmp_ptr->color_used;
274 } 266 }
275 uint8_t* src_pal_ptr = NULL; 267 uint8_t* src_pal_ptr = NULL;
276 FX_DWORD src_pal_size = bmp_ptr->pal_num * (bmp_ptr->pal_type ? 3 : 4); 268 FX_DWORD src_pal_size = bmp_ptr->pal_num * (bmp_ptr->pal_type ? 3 : 4);
277 if (_bmp_read_data(bmp_ptr, (uint8_t**)&src_pal_ptr, src_pal_size) == 269 if (_bmp_read_data(bmp_ptr, (uint8_t**)&src_pal_ptr, src_pal_size) ==
278 NULL) { 270 NULL) {
279 bmp_ptr->skip_size = skip_size_org; 271 bmp_ptr->skip_size = skip_size_org;
280 return 2; 272 return 2;
281 } 273 }
282 if (bmp_ptr->pal_ptr != NULL) { 274 FX_Free(bmp_ptr->pal_ptr);
283 FX_Free(bmp_ptr->pal_ptr);
284 bmp_ptr->pal_ptr = NULL;
285 }
286 bmp_ptr->pal_ptr = FX_Alloc(FX_DWORD, bmp_ptr->pal_num); 275 bmp_ptr->pal_ptr = FX_Alloc(FX_DWORD, bmp_ptr->pal_num);
287 BMP_PTR_NOT_NULL(bmp_ptr->pal_ptr, bmp_ptr);
288 int32_t src_pal_index = 0; 276 int32_t src_pal_index = 0;
289 if (bmp_ptr->pal_type == BMP_PAL_OLD) { 277 if (bmp_ptr->pal_type == BMP_PAL_OLD) {
290 while (src_pal_index < bmp_ptr->pal_num) { 278 while (src_pal_index < bmp_ptr->pal_num) {
291 bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE( 279 bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE(
292 0x00, src_pal_ptr[2], src_pal_ptr[1], src_pal_ptr[0]); 280 0x00, src_pal_ptr[2], src_pal_ptr[1], src_pal_ptr[0]);
293 src_pal_ptr += 3; 281 src_pal_ptr += 3;
294 } 282 }
295 } else { 283 } else {
296 while (src_pal_index < bmp_ptr->pal_num) { 284 while (src_pal_index < bmp_ptr->pal_num) {
297 bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE( 285 bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 633 }
646 void _bmp_input_buffer(bmp_decompress_struct_p bmp_ptr, 634 void _bmp_input_buffer(bmp_decompress_struct_p bmp_ptr,
647 uint8_t* src_buf, 635 uint8_t* src_buf,
648 FX_DWORD src_size) { 636 FX_DWORD src_size) {
649 bmp_ptr->next_in = src_buf; 637 bmp_ptr->next_in = src_buf;
650 bmp_ptr->avail_in = src_size; 638 bmp_ptr->avail_in = src_size;
651 bmp_ptr->skip_size = 0; 639 bmp_ptr->skip_size = 0;
652 } 640 }
653 FX_DWORD _bmp_get_avail_input(bmp_decompress_struct_p bmp_ptr, 641 FX_DWORD _bmp_get_avail_input(bmp_decompress_struct_p bmp_ptr,
654 uint8_t** avial_buf_ptr) { 642 uint8_t** avial_buf_ptr) {
655 if (avial_buf_ptr != NULL) { 643 if (avial_buf_ptr) {
656 *avial_buf_ptr = NULL; 644 *avial_buf_ptr = NULL;
657 if (bmp_ptr->avail_in > 0) { 645 if (bmp_ptr->avail_in > 0) {
658 *avial_buf_ptr = bmp_ptr->next_in; 646 *avial_buf_ptr = bmp_ptr->next_in;
659 } 647 }
660 } 648 }
661 return bmp_ptr->avail_in; 649 return bmp_ptr->avail_in;
662 } 650 }
663 bmp_compress_struct_p _bmp_create_compress() { 651 bmp_compress_struct_p _bmp_create_compress() {
664 bmp_compress_struct_p bmp_ptr; 652 bmp_compress_struct_p bmp_ptr;
665 bmp_ptr = FX_Alloc(bmp_compress_struct, 1); 653 bmp_ptr = FX_Alloc(bmp_compress_struct, 1);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 break; 954 break;
967 case BMP_RLE4: 955 case BMP_RLE4:
968 _bmp_encode_rle4(bmp_ptr, dst_buf, dst_size); 956 _bmp_encode_rle4(bmp_ptr, dst_buf, dst_size);
969 break; 957 break;
970 default:; 958 default:;
971 } 959 }
972 bmp_ptr->file_header.bfSize = dst_size; 960 bmp_ptr->file_header.bfSize = dst_size;
973 WriteFileHeader(&bmp_ptr->file_header, dst_buf); 961 WriteFileHeader(&bmp_ptr->file_header, dst_buf);
974 return TRUE; 962 return TRUE;
975 } 963 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/lbmp/fx_bmp.h ('k') | core/src/fxcodec/lgif/fx_gif.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698