Skip to content

Commit

Permalink
cppcheck: add const to pointers
Browse files Browse the repository at this point in the history
Found with constVariablePointer

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Nov 27, 2023
1 parent f9845b3 commit 55fffbb
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/crwimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(preview->pData() - pData);
(pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormatLength"] = static_cast<uint32_t>(preview->size());
}
Expand Down
2 changes: 1 addition & 1 deletion src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte*>(&value);
auto source_value = reinterpret_cast<const byte*>(&value);
auto destination_value = reinterpret_cast<byte*>(&result);

for (int i = 0; i < 8; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exiv2::Internal::TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const Exiv2::Internal::TiffEntryBase*>(finder.result());
return (!te || !te->pValue()) ? nullptr : te->pValue();
}

Expand Down
2 changes: 1 addition & 1 deletion src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ PrimaryGroups TiffParserWorker::findPrimaryGroups(TiffComponent* pSourceDir) {
for (auto imageGroup : imageGroups) {
TiffFinder finder(0x00fe, imageGroup);
pSourceDir->accept(finder);
auto te = dynamic_cast<TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const TiffEntryBase*>(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());
Expand Down
18 changes: 8 additions & 10 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const TiffEntryBase*>(finder.result());
if (te && te->pValue()) {
make_ = te->pValue()->toString();
}
Expand Down Expand Up @@ -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<TiffEntryBase*>(finder.result());
if (te) {
if (auto te = dynamic_cast<const TiffEntryBase*>(finder.result())) {
pData = te->pData();
size = te->size();
return;
Expand Down Expand Up @@ -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<TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const TiffEntryBase*>(finder.result());
if (te && te->pValue()) {
make_ = te->pValue()->toString();
}
Expand Down Expand Up @@ -590,7 +589,7 @@ void TiffEncoder::visitDirectoryNext(TiffDirectory* object) {
}

uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffComponent* pTiffComponent) {
auto pTiffEntry = dynamic_cast<TiffEntryBase*>(pTiffComponent);
auto pTiffEntry = dynamic_cast<const TiffEntryBase*>(pTiffComponent);
if (!pTiffEntry)
return 0;
us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder);
Expand Down Expand Up @@ -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<TiffImageEntry*>(finder.result());
if (ti) {
if (auto ti = dynamic_cast<const TiffImageEntry*>(finder.result())) {
object->strips_ = ti->strips_;
}
}
Expand Down Expand Up @@ -1014,7 +1012,7 @@ void TiffReader::readDataEntryBase(TiffDataEntryBase* object) {
readTiffEntry(object);
TiffFinder finder(object->szTag(), object->szGroup());
pRoot_->accept(finder);
auto te = dynamic_cast<TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const TiffEntryBase*>(finder.result());
if (te && te->pValue()) {
object->setStrips(te->pValue(), pData_, size_, baseOffset());
}
Expand Down Expand Up @@ -1187,7 +1185,7 @@ void TiffReader::visitMnEntry(TiffMnEntry* object) {
// Find camera make
TiffFinder finder(0x010f, IfdId::ifd0Id);
pRoot_->accept(finder);
auto te = dynamic_cast<TiffEntryBase*>(finder.result());
auto te = dynamic_cast<const TiffEntryBase*>(finder.result());
std::string make;
if (te && te->pValue()) {
make = te->pValue()->toString();
Expand Down Expand Up @@ -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<TiffEntryBase*>(finder.result())) {
if (auto te = dynamic_cast<const TiffEntryBase*>(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
Expand Down
6 changes: 3 additions & 3 deletions src/webpimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const byte*>(WEBP_CHUNK_HEADER_VP8X), WEBP_TAG_SIZE);
iIo.write(size, WEBP_TAG_SIZE);
Expand Down

0 comments on commit 55fffbb

Please sign in to comment.