Mercurial > octave-libtiff
changeset 31181:8a4ef572077d
__tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Thu, 18 Aug 2022 00:25:42 +0200 |
parents | ae78937e24d2 |
children | 4c8b8c400a3b |
files | libinterp/corefcn/__tiff__.cc |
diffstat | 1 files changed, 11 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc Thu Aug 18 00:11:23 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Thu Aug 18 00:25:42 2022 +0200 @@ -121,15 +121,11 @@ void - validate_tiff_get_field (bool status, void *p_to_free=NULL) + validate_tiff_get_field (bool status) { // Check if the return status of TIFFGetField is not 1 if (status != 1) - { - if (p_to_free != NULL) - _TIFFfree (p_to_free); - error ("Failed to read tag"); - } + error ("Failed to read tag"); } uint32_t get_rows_in_strip (uint32_t strip_no, uint32_t strip_count, @@ -937,11 +933,11 @@ typedef typename T::element_type P; T arr (arr_dims); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < arr_dims.numel (); i++) { arr(i) = (reinterpret_cast<P *> (data))[i]; } - retval = octave_value (arr); + return octave_value (arr); } octave_value @@ -1045,21 +1041,21 @@ int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); - // TODO(maged): convert to unique_ptr - void *data = _TIFFmalloc (type_size); + std::unique_ptr<uint8_t []> data + = std::make_unique<uint8_t []> (type_size); + uint8_t *data_ptr = data.get (); if (tag_id == TIFFTAG_PLANARCONFIG) { // Workaround for a bug in LibTIFF where it incorrectly returns // zero as the default value for PlanaConfiguration - if (! TIFFGetField(tif, tag_id, data)) - *reinterpret_cast<uint16_t *> (data) = 1; + if (! TIFFGetField(tif, tag_id, data_ptr)) + *reinterpret_cast<uint16_t *> (data_ptr) = 1; } else - validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data), data); + validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data_ptr)); - octave_value tag_data_ov = interpret_tag_data (data, 1, + octave_value tag_data_ov = interpret_tag_data (data_ptr, 1, TIFFFieldDataType (fip)); - _TIFFfree (data); return tag_data_ov; }