From 55fffbb97ec8b787451a7145e2dacb2dd237910c Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 26 Nov 2023 12:36:11 -0800 Subject: [PATCH] cppcheck: add const to pointers Found with constVariablePointer Signed-off-by: Rosen Penev --- src/basicio.cpp | 3 +-- src/crwimage.cpp | 3 +-- src/image.cpp | 2 +- src/makernote_int.cpp | 2 +- src/tiffimage_int.cpp | 2 +- src/tiffvisitor_int.cpp | 18 ++++++++---------- src/webpimage.cpp | 6 +++--- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index f2bacd82..4de704e7 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -1314,8 +1314,7 @@ byte* RemoteIo::mmap(bool /*isWriteable*/) { size_t blocks = (p_->size_ + blockSize - 1) / blockSize; bigBlock_ = new byte[blocks * blockSize]; for (size_t block = 0; block < blocks; block++) { - auto p = p_->blocksMap_[block].getData(); - if (p) { + if (auto p = p_->blocksMap_[block].getData()) { size_t nRead = block == (blocks - 1) ? p_->size_ - nRealData : blockSize; memcpy(bigBlock_ + (block * blockSize), p, nRead); nRealData += nRead; diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 9460b27b..0894bafb 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -106,8 +106,7 @@ void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) { header.decode(*pCrwImage); // a hack to get absolute offset of preview image inside CRW structure - auto preview = header.findComponent(0x2007, 0x0000); - if (preview) { + if (auto preview = header.findComponent(0x2007, 0x0000)) { (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormat"] = static_cast(preview->pData() - pData); (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormatLength"] = static_cast(preview->size()); } diff --git a/src/image.cpp b/src/image.cpp index ea3534a1..3ca55d14 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -208,7 +208,7 @@ uint64_t Image::byteSwap(uint64_t value, bool bSwap) { return bSwap ? std::byteswap(value) : value; #else uint64_t result = 0; - auto source_value = reinterpret_cast(&value); + auto source_value = reinterpret_cast(&value); auto destination_value = reinterpret_cast(&result); for (int i = 0; i < 8; i++) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index d8aae80f..44332ae8 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -1048,7 +1048,7 @@ const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const ui if (!pRoot) return nullptr; pRoot->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); return (!te || !te->pValue()) ? nullptr : te->pValue(); } diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 2e33ebac..bd677cc7 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -2127,7 +2127,7 @@ PrimaryGroups TiffParserWorker::findPrimaryGroups(TiffComponent* pSourceDir) { for (auto imageGroup : imageGroups) { TiffFinder finder(0x00fe, imageGroup); pSourceDir->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); const Value* pV = te ? te->pValue() : nullptr; if (pV && pV->typeId() == unsignedLong && pV->count() == 1 && (pV->toInt64() & 1) == 0) { ret.push_back(te->group()); diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 6d9bd927..a06f253f 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -195,7 +195,7 @@ TiffDecoder::TiffDecoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpDat // Find camera make by looking for tag 0x010f in IFD0 TiffFinder finder(0x010f, IfdId::ifd0Id); pRoot_->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { make_ = te->pValue()->toString(); } @@ -253,8 +253,7 @@ void TiffDecoder::getObjData(const byte*& pData, size_t& size, uint16_t tag, Ifd } TiffFinder finder(tag, group); pRoot_->accept(finder); - auto te = dynamic_cast(finder.result()); - if (te) { + if (auto te = dynamic_cast(finder.result())) { pData = te->pData(); size = te->size(); return; @@ -467,7 +466,7 @@ TiffEncoder::TiffEncoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpDat if (make_.empty() && pRoot_) { TiffFinder finder(0x010f, IfdId::ifd0Id); pRoot_->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { make_ = te->pValue()->toString(); } @@ -590,7 +589,7 @@ void TiffEncoder::visitDirectoryNext(TiffDirectory* object) { } uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffComponent* pTiffComponent) { - auto pTiffEntry = dynamic_cast(pTiffComponent); + auto pTiffEntry = dynamic_cast(pTiffComponent); if (!pTiffEntry) return 0; us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder); @@ -847,8 +846,7 @@ void TiffEncoder::encodeImageEntry(TiffImageEntry* object, const Exifdatum* datu if (pSourceTree_) { TiffFinder finder(object->tag(), object->group()); pSourceTree_->accept(finder); - auto ti = dynamic_cast(finder.result()); - if (ti) { + if (auto ti = dynamic_cast(finder.result())) { object->strips_ = ti->strips_; } } @@ -1014,7 +1012,7 @@ void TiffReader::readDataEntryBase(TiffDataEntryBase* object) { readTiffEntry(object); TiffFinder finder(object->szTag(), object->szGroup()); pRoot_->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { object->setStrips(te->pValue(), pData_, size_, baseOffset()); } @@ -1187,7 +1185,7 @@ void TiffReader::visitMnEntry(TiffMnEntry* object) { // Find camera make TiffFinder finder(0x010f, IfdId::ifd0Id); pRoot_->accept(finder); - auto te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); std::string make; if (te && te->pValue()) { make = te->pValue()->toString(); @@ -1348,7 +1346,7 @@ void TiffReader::visitBinaryArray(TiffBinaryArray* object) { // Check duplicates TiffFinder finder(object->tag(), object->group()); pRoot_->accept(finder); - if (auto te = dynamic_cast(finder.result())) { + if (auto te = dynamic_cast(finder.result())) { if (te->idx() != object->idx()) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Not decoding duplicate binary array tag 0x" << std::setw(4) << std::setfill('0') << std::hex diff --git a/src/webpimage.cpp b/src/webpimage.cpp index f8d0f463..87fbcba6 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -586,8 +586,8 @@ void WebPImage::decodeChunks(uint32_t filesize) { // 4 meaningful bytes + 2 padding bytes byte exifLongHeader[] = {0xFF, 0x01, 0xFF, 0xE1, 0x00, 0x00}; byte exifShortHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; - byte exifTiffLEHeader[] = {0x49, 0x49, 0x2A}; // "MM*" - byte exifTiffBEHeader[] = {0x4D, 0x4D, 0x00, 0x2A}; // "II\0*" + const byte exifTiffLEHeader[] = {0x49, 0x49, 0x2A}; // "MM*" + const byte exifTiffBEHeader[] = {0x4D, 0x4D, 0x00, 0x2A}; // "II\0*" size_t offset = 0; bool s_header = false; bool le_header = false; @@ -727,7 +727,7 @@ bool WebPImage::equalsWebPTag(const Exiv2::DataBuf& buf, const char* str) { */ void WebPImage::inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_alpha, bool has_icc, uint32_t width, uint32_t height) const { - byte size[4] = {0x0A, 0x00, 0x00, 0x00}; + const byte size[4] = {0x0A, 0x00, 0x00, 0x00}; byte data[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; iIo.write(reinterpret_cast(WEBP_CHUNK_HEADER_VP8X), WEBP_TAG_SIZE); iIo.write(size, WEBP_TAG_SIZE);