A few more minor fixes geared towards lgtm.com alerts (#6127)

* Remove unfilled formatting placeholders in KLT parser.
* Fix presumably unintentionally missing reference on PlanatPtr and ChunkyPtr call operators.
* Fix catching pointer and make use-after-free of workimg easier to spot.
Make sure all of our thrown exceptions derive from std::exception and then catch
by reference instead of by pointer.
* Fix mismatch between array form new and non-array form delete.
* Simplify memory management of embedded color profiles by unifying allocation to use operator new.
This commit is contained in:
Adam Reichold
2021-03-17 08:37:19 +01:00
committed by GitHub
parent 537fa73d3f
commit fae40a137a
9 changed files with 22 additions and 37 deletions

View File

@@ -18,7 +18,7 @@
*/
#include "iccjpeg.h"
#include <cstdlib> /* define malloc() */
#include <new>
/*
@@ -155,12 +155,9 @@ marker_is_icc (jpeg_saved_marker_ptr marker)
* If TRUE is returned, *icc_data_ptr is set to point to the
* returned data, and *icc_data_len is set to its length.
*
* IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
* and must be freed by the caller with free() when the caller no longer
* needs it. (Alternatively, we could write this routine to use the
* IJG library's memory allocator, so that the data would be freed implicitly
* at jpeg_finish_decompress() time. But it seems likely that many apps
* will prefer to have the data stick around after decompression finishes.)
* IMPORTANT: the data at **icc_data_ptr has been allocated with new
* and must be freed by the caller with delete[] when the caller no longer
* needs it.
*
* NOTE: if the file contains invalid ICC APP2 markers, we just silently
* return FALSE. You might want to issue an error message instead.
@@ -235,7 +232,7 @@ read_icc_profile (j_decompress_ptr cinfo,
}
/* Allocate space for assembled data */
icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET));
icc_data = new (std::nothrow) JOCTET[total_length];
if (icc_data == nullptr) {
return FALSE; /* oops, out of memory */