From b05573fadc5ba792ec1e929eb56fe2b8c9be6a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Tue, 22 Mar 2022 15:25:08 +0100 Subject: [PATCH] Remove most of the asserts from codebase --- app/actions.cpp | 21 ------------- app/exiv2.cpp | 7 ++--- samples/addmoddel.cpp | 1 - samples/convert-test.cpp | 1 - samples/easyaccess-test.cpp | 1 - samples/exifcomment.cpp | 1 - samples/exifdata-test.cpp | 1 - samples/exifdata.cpp | 1 - samples/exiv2json.cpp | 2 -- samples/largeiptc-test.cpp | 1 - samples/mrwthumb.cpp | 1 - samples/remotetest.cpp | 1 - samples/tiff-test.cpp | 3 -- samples/xmpprint.cpp | 1 - src/basicio.cpp | 21 ------------- src/bmffimage.cpp | 1 - src/cr2header_int.cpp | 3 +- src/crwimage.cpp | 3 -- src/crwimage_int.cpp | 34 -------------------- src/error.cpp | 5 ++- src/image.cpp | 2 -- src/image_int.cpp | 2 -- src/jpgimage.cpp | 14 --------- src/makernote_int.cpp | 5 --- src/orfimage_int.cpp | 3 +- src/pngchunk_int.cpp | 8 +---- src/pngimage.cpp | 2 +- src/tags.cpp | 2 -- src/tiffcomposite_int.cpp | 32 ++----------------- src/tiffimage_int.cpp | 4 --- src/tiffvisitor_int.cpp | 62 ------------------------------------- src/types.cpp | 7 ----- src/value.cpp | 6 ---- 33 files changed, 10 insertions(+), 249 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index 28470fd0..2fecfc97 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -241,7 +241,6 @@ int Print::printSummary() { } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); align_ = 16; @@ -361,7 +360,6 @@ int Print::printList() { } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); // Set defaults for metadata types and data columns if (Params::instance().printTags_ == Exiv2::mdNone) { @@ -566,7 +564,6 @@ int Print::printComment() { } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); if (Params::instance().verbose_) { std::cout << _("JPEG comment") << ": "; @@ -582,7 +579,6 @@ int Print::printPreviewList() { } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); bool const manyFiles = Params::instance().files_.size() > 1; int cnt = 0; @@ -616,7 +612,6 @@ int Rename::run(const std::string& path) { ts.read(path); auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); if (exifData.empty()) { @@ -686,7 +681,6 @@ int Erase::run(const std::string& path) { ts.read(path); auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); // Thumbnail must be before Exif int rc = 0; @@ -829,7 +823,6 @@ int Extract::writeThumbnail() const { return -1; } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); if (exifData.empty()) { @@ -874,7 +867,6 @@ int Extract::writePreviews() const { } auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); Exiv2::PreviewManager pvMgr(*image); @@ -911,7 +903,6 @@ int Extract::writeIccProfile(const std::string& target) const { if (rc == 0) { auto image = Exiv2::ImageFactory::open(path_); - assert(image); image->readMetadata(); if (!image->iccProfileDefined()) { std::cerr << _("No embedded iccProfile: ") << path_ << std::endl; @@ -1034,7 +1025,6 @@ int Insert::insertXmpPacket(const std::string& path, const Exiv2::DataBuf& xmpBl xmpPacket += static_cast(xmpBlob.read_uint8(i)); } auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); image->clearXmpData(); image->setXmpPacket(xmpPacket); @@ -1075,7 +1065,6 @@ int Insert::insertIccProfile(const std::string& path, Exiv2::DataBuf&& iccProfil // read in the metadata if (rc == 0) { auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); // clear existing profile, assign the blob and rewrite image image->clearIccProfile(); @@ -1099,7 +1088,6 @@ int Insert::insertThumbnail(const std::string& path) { return -1; } auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); Exiv2::ExifThumb exifThumb(image->exifData()); exifThumb.setJpegThumbnail(thumbPath); @@ -1123,7 +1111,6 @@ int Modify::run(const std::string& path) { ts.read(path); auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); int rc = applyCommands(image.get()); @@ -1174,7 +1161,6 @@ int Modify::applyCommands(Exiv2::Image* pImage) { regNamespace(cmd); break; case invalidCmdId: - assert(invalidCmdId == cmd.cmdId_); break; } } @@ -1334,7 +1320,6 @@ int Adjust::run(const std::string& path) try { ts.read(path); auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); if (exifData.empty()) { @@ -1452,7 +1437,6 @@ int FixIso::run(const std::string& path) { ts.read(path); auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); if (exifData.empty()) { @@ -1501,7 +1485,6 @@ int FixCom::run(const std::string& path) { ts.read(path); auto image = Exiv2::ImageFactory::open(path); - assert(image); image->readMetadata(); Exiv2::ExifData& exifData = image->exifData(); if (exifData.empty()) { @@ -1691,7 +1674,6 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType sourceImage = Exiv2::ImageFactory::open(source); } - assert(sourceImage); sourceImage->readMetadata(); // Apply any modification commands to the source image on-the-fly @@ -1703,11 +1685,9 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType std::unique_ptr targetImage; if (Exiv2::fileExists(target)) { targetImage = Exiv2::ImageFactory::open(target); - assert(targetImage); targetImage->readMetadata(); } else { targetImage = Exiv2::ImageFactory::create(targetType, target); - assert(targetImage); } // Copy each type of metadata @@ -1932,7 +1912,6 @@ int printStructure(std::ostream& out, Exiv2::PrintStructureOption option, const return -1; } Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(path); - assert(image.get() != 0); image->printStructure(out, option); return 0; } diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 9f420934..bb1dd8c7 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -12,7 +12,6 @@ #include "i18n.h" // NLS support. #include "xmp_exiv2.hpp" -#include #include #include #include @@ -136,9 +135,7 @@ int main(int argc, char* const argv[]) { try { // Create the required action class - Action::TaskFactory& taskFactory = Action::TaskFactory::instance(); - auto task = taskFactory.create(Action::TaskType(params.action_)); - assert(task); + auto task = Action::TaskFactory::instance().create(Action::TaskType(params.action_)); // Process all files auto filesCount = params.files_.size(); @@ -160,7 +157,7 @@ int main(int argc, char* const argv[]) { returnCode = ret; } - taskFactory.cleanup(); + Action::TaskFactory::instance().cleanup(); Exiv2::XmpParser::terminate(); } } catch (const std::exception& exc) { diff --git a/samples/addmoddel.cpp b/samples/addmoddel.cpp index 0b3b1380..c3aa38fe 100644 --- a/samples/addmoddel.cpp +++ b/samples/addmoddel.cpp @@ -3,7 +3,6 @@ #include -#include #include int main(int argc, char* const argv[]) { diff --git a/samples/convert-test.cpp b/samples/convert-test.cpp index da5a1bae..62a0b127 100644 --- a/samples/convert-test.cpp +++ b/samples/convert-test.cpp @@ -3,7 +3,6 @@ #include -#include #include int main(int argc, char* const argv[]) { diff --git a/samples/easyaccess-test.cpp b/samples/easyaccess-test.cpp index 7ad5d65c..8dbe72be 100644 --- a/samples/easyaccess-test.cpp +++ b/samples/easyaccess-test.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Sample program using high-level metadata access functions -#include #include #include #include diff --git a/samples/exifcomment.cpp b/samples/exifcomment.cpp index 45440995..355f564d 100644 --- a/samples/exifcomment.cpp +++ b/samples/exifcomment.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Abstract : Sample program showing how to set the Exif comment of an image, Exif.Photo.UserComment -#include #include #include diff --git a/samples/exifdata-test.cpp b/samples/exifdata-test.cpp index 6b74f77e..38223455 100644 --- a/samples/exifdata-test.cpp +++ b/samples/exifdata-test.cpp @@ -23,7 +23,6 @@ int main(int argc, char* const argv[]) { std::string file(argv[1]); auto image = Exiv2::ImageFactory::open(file); - assert(image); image->readMetadata(); Exiv2::ExifData& ed = image->exifData(); diff --git a/samples/exifdata.cpp b/samples/exifdata.cpp index 3442e1f8..b5a457fa 100644 --- a/samples/exifdata.cpp +++ b/samples/exifdata.cpp @@ -3,7 +3,6 @@ #include -#include #include #include diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index 346a662a..7e775329 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -5,7 +5,6 @@ #include -#include #include #include #include @@ -262,7 +261,6 @@ int main(int argc, char* const argv[]) { char option = opt[0]; Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(path); - assert(image.get() != 0); image->readMetadata(); Jzon::Object root; diff --git a/samples/largeiptc-test.cpp b/samples/largeiptc-test.cpp index 6ab67cdc..e605e0fc 100644 --- a/samples/largeiptc-test.cpp +++ b/samples/largeiptc-test.cpp @@ -3,7 +3,6 @@ // Test for large (>65535 bytes) IPTC buffer // ***************************************************************** -*- C++ -*- -#include #include #include diff --git a/samples/mrwthumb.cpp b/samples/mrwthumb.cpp index 5ea82945..cf6fa455 100644 --- a/samples/mrwthumb.cpp +++ b/samples/mrwthumb.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Sample program to extract a Minolta thumbnail from the makernote -#include #include #include diff --git a/samples/remotetest.cpp b/samples/remotetest.cpp index c98ec8a0..1fa845e1 100644 --- a/samples/remotetest.cpp +++ b/samples/remotetest.cpp @@ -3,7 +3,6 @@ // It makes some modifications on the metadata of remote file, reads new metadata from that file // and reset the metadata back to the original status. -#include #include #include #include diff --git a/samples/tiff-test.cpp b/samples/tiff-test.cpp index 0ad85c3e..761cf0a2 100644 --- a/samples/tiff-test.cpp +++ b/samples/tiff-test.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -45,14 +44,12 @@ void mini1(const char* path) { // Write nothing to a new structure, without a previous binary image wm = ExifParser::encode(blob, nullptr, 0, bigEndian, exifData); enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value"); - assert(blob.empty()); std::cout << "Test 1: Writing empty Exif data without original binary data: ok.\n"; // Write nothing, this time with a previous binary image DataBuf buf = readFile(path); wm = ExifParser::encode(blob, buf.c_data(), buf.size(), bigEndian, exifData); enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value"); - assert(blob.empty()); std::cout << "Test 2: Writing empty Exif data with original binary data: ok.\n"; // Write something to a new structure, without a previous binary image diff --git a/samples/xmpprint.cpp b/samples/xmpprint.cpp index 1d0048f9..865901ea 100644 --- a/samples/xmpprint.cpp +++ b/samples/xmpprint.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Read an XMP from a video or graphic file, parse it and print all (known) properties. -#include #include #include #include diff --git a/src/basicio.cpp b/src/basicio.cpp index 49b221d2..361f52aa 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -120,7 +120,6 @@ FileIo::Impl::Impl(std::string path) : path_(std::move(path)) { } int FileIo::Impl::switchMode(OpMode opMode) { - assert(fp_); if (opMode_ == opMode) return 0; OpMode oldOpMode = opMode_; @@ -225,7 +224,6 @@ int FileIo::munmap() { } byte* FileIo::mmap(bool isWriteable) { - assert(p_->fp_); if (munmap() != 0) { throw Error(ErrorCode::kerCallFailed, path(), strError(), "munmap"); } @@ -297,14 +295,12 @@ void FileIo::setPath(const std::string& path) { } size_t FileIo::write(const byte* data, size_t wcount) { - assert(p_->fp_); if (p_->switchMode(Impl::opWrite) != 0) return 0; return std::fwrite(data, 1, wcount, p_->fp_); } size_t FileIo::write(BasicIo& src) { - assert(p_->fp_); if (static_cast(this) == &src) return 0; if (!src.isopen()) @@ -434,15 +430,12 @@ void FileIo::transfer(BasicIo& src) { } // FileIo::transfer int FileIo::putb(byte data) { - assert(p_->fp_); if (p_->switchMode(Impl::opWrite) != 0) return EOF; return putc(data, p_->fp_); } int FileIo::seek(int64_t offset, Position pos) { - assert(p_->fp_); - int fileSeek = 0; switch (pos) { case BasicIo::cur: @@ -466,7 +459,6 @@ int FileIo::seek(int64_t offset, Position pos) { } long FileIo::tell() const { - assert(p_->fp_); return std::ftell(p_->fp_); } @@ -520,7 +512,6 @@ int FileIo::close() { } DataBuf FileIo::read(size_t rcount) { - assert(p_->fp_); if (rcount > size()) throw Error(ErrorCode::kerInvalidMalloc); DataBuf buf(rcount); @@ -533,7 +524,6 @@ DataBuf FileIo::read(size_t rcount) { } size_t FileIo::read(byte* buf, size_t rcount) { - assert(p_->fp_); if (p_->switchMode(Impl::opRead) != 0) { return 0; } @@ -541,7 +531,6 @@ size_t FileIo::read(byte* buf, size_t rcount) { } int FileIo::getb() { - assert(p_->fp_); if (p_->switchMode(Impl::opRead) != 0) return EOF; return getc(p_->fp_); @@ -613,7 +602,6 @@ class EXIV2API BlockMap { //! @param source The data populate to the block //! @param num The size of data void populate(byte* source, size_t num) { - assert(source); size_ = num; data_ = new byte[size_]; type_ = bMemory; @@ -704,7 +692,6 @@ MemIo::~MemIo() { size_t MemIo::write(const byte* data, size_t wcount) { p_->reserve(wcount); - assert(p_->isMalloced_); if (data) { std::memcpy(&p_->data_[p_->idx_], data, wcount); } @@ -759,7 +746,6 @@ size_t MemIo::write(BasicIo& src) { int MemIo::putb(byte data) { p_->reserve(1); - assert(p_->isMalloced_); p_->data_[p_->idx_++] = data; return data; } @@ -1068,8 +1054,6 @@ RemoteIo::Impl::Impl(const std::string& url, size_t blockSize) : } size_t RemoteIo::Impl::populateBlocks(size_t lowBlock, size_t highBlock) { - assert(isMalloced_); - // optimize: ignore all true blocks on left & right sides. while (!blocksMap_[lowBlock].isNone() && lowBlock < highBlock) lowBlock++; @@ -1165,7 +1149,6 @@ size_t RemoteIo::write(const byte* /* unused data*/, size_t /* unused wcount*/) } size_t RemoteIo::write(BasicIo& src) { - assert(p_->isMalloced_); if (!src.isopen()) return 0; @@ -1249,7 +1232,6 @@ DataBuf RemoteIo::read(size_t rcount) { } size_t RemoteIo::read(byte* buf, size_t rcount) { - assert(p_->isMalloced_); if (p_->eof_) return 0; p_->totalRead_ += rcount; @@ -1288,7 +1270,6 @@ size_t RemoteIo::read(byte* buf, size_t rcount) { } int RemoteIo::getb() { - assert(p_->isMalloced_); if (p_->idx_ == p_->size_) { p_->eof_ = true; return EOF; @@ -1311,7 +1292,6 @@ void RemoteIo::transfer(BasicIo& src) { } int RemoteIo::seek(int64_t offset, Position pos) { - assert(p_->isMalloced_); int64_t newIdx = 0; switch (pos) { @@ -1386,7 +1366,6 @@ const std::string& RemoteIo::path() const noexcept { } void RemoteIo::populateFakeData() { - assert(p_->isMalloced_); size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_; for (size_t i = 0; i < nBlocks; i++) { if (p_->blocksMap_[i].isNone()) diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index 3c1b13a7..a293179c 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -16,7 +16,6 @@ #include "types.hpp" // + standard includes -#include #include #include #include diff --git a/src/cr2header_int.cpp b/src/cr2header_int.cpp index 77ee0c24..ecb341b6 100644 --- a/src/cr2header_int.cpp +++ b/src/cr2header_int.cpp @@ -37,8 +37,7 @@ DataBuf Cr2Header::write() const { case bigEndian: buf.write_uint8(0, 'M'); break; - case invalidByteOrder: - assert(false); + default: break; } buf.write_uint8(1, buf.read_uint8(0)); diff --git a/src/crwimage.cpp b/src/crwimage.cpp index f5763858..84bc9442 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -101,9 +101,6 @@ void CrwImage::writeMetadata() { } // CrwImage::writeMetadata void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) { - assert(pCrwImage); - assert(pData); - // Parse the image, starting with a CIFF header component CiffHeader header; header.read(pData, size); diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 5e8c4a78..c0a707c1 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -6,7 +6,6 @@ #include "error.hpp" #include "i18n.h" // NLS support. -#include #include #include @@ -188,7 +187,6 @@ void CiffComponent::doRead(const byte* pData, size_t size, uint32_t start, ByteO tag_ = getUShort(pData + start, byteOrder); DataLocId dl = dataLocation(); - assert(dl == directoryData || dl == valueData); if (dl == valueData) { size_ = getULong(pData + start + 2, byteOrder); @@ -288,7 +286,6 @@ void CiffDirectory::doDecode(Image& image, ByteOrder byteOrder) const { } // CiffDirectory::doDecode void CiffHeader::write(Blob& blob) const { - assert(byteOrder_ == littleEndian || byteOrder_ == bigEndian); if (byteOrder_ == littleEndian) { blob.push_back('I'); blob.push_back('I'); @@ -305,7 +302,6 @@ void CiffHeader::write(Blob& blob) const { o += 8; // Pad as needed if (!pPadding_.empty()) { - assert(padded_ == offset_ - o); append(blob, pPadding_.data(), padded_); } else { for (uint32_t i = o; i < offset_; ++i) { @@ -392,7 +388,6 @@ void CiffComponent::writeDirEntry(Blob& blob, ByteOrder byteOrder) const { byte buf[4]; DataLocId dl = dataLocation(); - assert(dl == directoryData || dl == valueData); if (dl == valueData) { us2Data(buf, tag_, byteOrder); @@ -407,7 +402,6 @@ void CiffComponent::writeDirEntry(Blob& blob, ByteOrder byteOrder) const { if (dl == directoryData) { // Only 8 bytes fit in the directory entry - assert(size_ <= 8); us2Data(buf, tag_, byteOrder); append(blob, buf, 2); @@ -527,7 +521,6 @@ void CiffHeader::add(uint16_t crwTagId, uint16_t crwDir, DataBuf&& buf) { CrwDirs crwDirs; CrwMap::loadStack(crwDirs, crwDir); [[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_; - assert(rootDirectory == 0x0000); crwDirs.pop(); if (!pRootDir_) { pRootDir_ = std::make_unique(); @@ -600,7 +593,6 @@ void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) { CrwDirs crwDirs; CrwMap::loadStack(crwDirs, crwDir); [[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_; - assert(rootDirectory == 0x0000); crwDirs.pop(); pRootDir_->remove(crwDirs, crwTagId); } @@ -725,7 +717,6 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p ifdId = canonPiId; break; } - assert(ifdId != ifdIdNotSet); std::string groupName(Internal::groupName(ifdId)); const size_t component_size = ciffComponent.size(); @@ -771,7 +762,6 @@ void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping* if (ciffComponent.size() < 8 || ciffComponent.typeId() != unsignedLong) { return decodeBasic(ciffComponent, pCrwMapping, image, byteOrder); } - assert(pCrwMapping != 0); ULongValue v; v.read(ciffComponent.pData(), 8, byteOrder); time_t t = v.value_.at(0); @@ -818,7 +808,6 @@ void CrwMap::decode0x2008(const CiffComponent& ciffComponent, const CrwMapping* void CrwMap::decodeBasic(const CiffComponent& ciffComponent, const CrwMapping* pCrwMapping, Image& image, ByteOrder byteOrder) { - assert(pCrwMapping != 0); // create a key and value pair ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); std::unique_ptr value; @@ -862,9 +851,6 @@ void CrwMap::encode(CiffHeader* pHead, const Image& image) { } // CrwMap::encode void CrwMap::encodeBasic(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - // Determine the source Exif metadatum ExifKey ek(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); auto ed = image.exifData().findKey(ek); @@ -880,9 +866,6 @@ void CrwMap::encodeBasic(const Image& image, const CrwMapping* pCrwMapping, Ciff } // CrwMap::encodeBasic void CrwMap::encode0x0805(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - std::string comment = image.comment(); CiffComponent* cc = pHead->findComponent(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); @@ -903,9 +886,6 @@ void CrwMap::encode0x0805(const Image& image, const CrwMapping* pCrwMapping, Cif } // CrwMap::encode0x0805 void CrwMap::encode0x080a(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - const ExifKey k1("Exif.Image.Make"); const ExifKey k2("Exif.Image.Model"); const auto ed1 = image.exifData().findKey(k1); @@ -928,7 +908,6 @@ void CrwMap::encode0x080a(const Image& image, const CrwMapping* pCrwMapping, Cif ed2->copy(buf.data(pos), pHead->byteOrder()); pos += ed2->size(); } - assert(pos == size); pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf)); } else { pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); @@ -936,9 +915,6 @@ void CrwMap::encode0x080a(const Image& image, const CrwMapping* pCrwMapping, Cif } void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - IfdId ifdId = ifdIdNotSet; switch (pCrwMapping->tag_) { case 0x0001: @@ -954,7 +930,6 @@ void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, Ciff ifdId = canonPiId; break; } - assert(ifdId != ifdIdNotSet); DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder()); if (buf.empty()) { // Try the undecoded tag @@ -970,9 +945,6 @@ void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, Ciff } // CrwMap::encodeArray void CrwMap::encode0x180e(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - time_t t = 0; const ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); const auto ed = image.exifData().findKey(key); @@ -993,9 +965,6 @@ void CrwMap::encode0x180e(const Image& image, const CrwMapping* pCrwMapping, Cif } // CrwMap::encode0x180e void CrwMap::encode0x1810(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - const ExifKey kX("Exif.Photo.PixelXDimension"); const ExifKey kY("Exif.Photo.PixelYDimension"); const ExifKey kO("Exif.Image.Orientation"); @@ -1034,9 +1003,6 @@ void CrwMap::encode0x1810(const Image& image, const CrwMapping* pCrwMapping, Cif } // CrwMap::encode0x1810 void CrwMap::encode0x2008(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) { - assert(pCrwMapping != 0); - assert(pHead != 0); - ExifThumbC exifThumb(image.exifData()); DataBuf buf = exifThumb.copy(); if (!buf.empty()) { diff --git a/src/error.cpp b/src/error.cpp index 36663d2a..dd2ed5c2 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -7,7 +7,6 @@ // + standard includes #include -#include #include namespace { @@ -144,8 +143,8 @@ void LogMsg::defaultHandler(int level, const char* s) { case LogMsg::error: std::cerr << "Error: "; break; - case LogMsg::mute: - assert(false); + default: + break; } std::cerr << s; } diff --git a/src/image.cpp b/src/image.cpp index f25e0b40..b8303358 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -38,7 +38,6 @@ #include "xmpsidecar.hpp" // + standard includes -#include #include #include #include @@ -851,7 +850,6 @@ Image::UniquePtr ImageFactory::create(ImageType type, BasicIo::UniquePtr io) { void append(Blob& blob, const byte* buf, size_t len) { if (len != 0) { - assert(buf); Blob::size_type size = blob.size(); if (blob.capacity() - size < len) { blob.reserve(size + 65536); diff --git a/src/image_int.cpp b/src/image_int.cpp index 2b54648e..6c498c3d 100644 --- a/src/image_int.cpp +++ b/src/image_int.cpp @@ -2,7 +2,6 @@ #include "image_int.hpp" -#include #include #include #include @@ -27,7 +26,6 @@ std::string stringFormat(const char* format, ...) { va_start(args, format); // args start after format rc = vsnprintf(&buffer[0], buffer.size(), format, args); va_end(args); // free the args - assert(rc >= 0); // rc < 0 => we have made an error in the format string if (rc > 0) need = static_cast(rc); } while (buffer.size() <= need); diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index eed5887b..e0dfde8e 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -39,7 +39,6 @@ bool Photoshop::isIrb(const byte* pPsData, size_t sizePsData) { if (sizePsData < 4) return false; for (auto&& i : irbId_) { - assert(strlen(i) == 4); if (memcmp(pPsData, i, 4) == 0) return true; } @@ -64,9 +63,6 @@ bool Photoshop::valid(const byte* pPsData, size_t sizePsData) { // if this also makes sense for psTag != Photoshop::iptc int Photoshop::locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record, uint32_t* const sizeHdr, uint32_t* const sizeData) { - assert(record); - assert(sizeHdr); - assert(sizeData); if (sizePsData < 12) { return 3; } @@ -147,8 +143,6 @@ int Photoshop::locatePreviewIrb(const byte* pPsData, size_t sizePsData, const by } DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const IptcData& iptcData) { - if (sizePsData > 0) - assert(pPsData); #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "IRB block at the beginning of Photoshop::setIptcIrb\n"; if (sizePsData == 0) @@ -498,7 +492,6 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, in // Read the rest of the segment. DataBuf buf(size); if (size > 0) { - assert(size >= 2); // enforced above io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); buf.copyBytes(0, sizebuf, 2); } @@ -508,8 +501,6 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, in // print signature for APPn if (marker >= app0_ && marker <= (app0_ | 0x0F)) { - assert(markerHasLength(marker)); - assert(size >= 2); // Because this marker has a length field. // http://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/XMPSpecificationPart3.pdf p75 const std::string signature = string_from_unterminated(buf.c_str(2), size - 2); @@ -646,8 +637,6 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, in // print COM marker if (bPrint && marker == com_) { - assert(markerHasLength(marker)); - assert(size >= 2); // Because this marker has a length field. // size includes 2 for the two bytes for size! const size_t n = (size - 2) > 32 ? 32 : size - 2; // start after the two bytes @@ -756,7 +745,6 @@ DataBuf JpegBase::readNextSegment(byte marker) { // Read the rest of the segment. DataBuf buf(size); if (size > 0) { - assert(size >= 2); // enforced above io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); buf.copyBytes(0, sizebuf, 2); } @@ -972,11 +960,9 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { const long chunk_size = 256 * 256 - 40; // leave bytes for marker, header and padding size_t size = iccProfile_.size(); - assert(size > 0); // Because iccProfileDefined() == true if (size >= 255 * chunk_size) throw Error(ErrorCode::kerTooLargeJpegSegment, "IccProfile"); const size_t chunks = 1 + (size - 1) / chunk_size; - assert(chunks <= 255); // Because size < 255 * chunk_size for (size_t chunk = 0; chunk < chunks; chunk++) { size_t bytes = size > chunk_size ? chunk_size : size; // bytes to write size -= bytes; diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 1048f578..0fdbdd98 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -133,7 +133,6 @@ TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::strin TiffComponent* tc = nullptr; const TiffMnRegistry* tmr = find(registry_, make); if (tmr) { - assert(tmr->newMnFct_); tc = tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder); } return tc; @@ -147,7 +146,6 @@ TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) { std::cout << "mnGroup = " << mnGroup << "\n"; } - assert(tmr->newMnFct2_); tc = tmr->newMnFct2_(tag, group, mnGroup); } return tc; @@ -355,8 +353,6 @@ bool Nikon3MnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder* } // Nikon3MnHeader::read size_t Nikon3MnHeader::write(IoWrapper& ioWrapper, ByteOrder byteOrder) const { - assert(buf_.size() >= 10); - ioWrapper.write(buf_.c_data(), 10); /// \todo: This removes any gap between the header and makernote IFD. The gap should be copied too. TiffHeader th(byteOrder); @@ -493,7 +489,6 @@ const byte SigmaMnHeader::signature1_[] = {'S', 'I', 'G', 'M', 'A', '\0', '\0', const byte SigmaMnHeader::signature2_[] = {'F', 'O', 'V', 'E', 'O', 'N', '\0', '\0', 0x01, 0x00}; size_t SigmaMnHeader::sizeOfSignature() { - assert(sizeof(signature1_) == sizeof(signature2_)); return sizeof(signature1_); } diff --git a/src/orfimage_int.cpp b/src/orfimage_int.cpp index 28194d7b..2483db06 100644 --- a/src/orfimage_int.cpp +++ b/src/orfimage_int.cpp @@ -35,8 +35,7 @@ DataBuf OrfHeader::write() const { case bigEndian: buf.write_uint8(0, 'M'); break; - case invalidByteOrder: - assert(false); + default: break; } buf.write_uint8(1, buf.read_uint8(0)); diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 30a1cb84..8a3cee9f 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -19,7 +19,6 @@ // standard includes #include -#include #include #include #include @@ -43,10 +42,7 @@ constexpr size_t nullSeparators = 2; // class member definitions namespace Exiv2::Internal { void PngChunk::decodeIHDRChunk(const DataBuf& data, uint32_t* outWidth, uint32_t* outHeight) { - assert(data.size() >= 8); - // Extract image width and height from IHDR chunk. - *outWidth = data.read_uint32(0, bigEndian); *outHeight = data.read_uint32(4, bigEndian); } @@ -340,7 +336,7 @@ std::string PngChunk::makeMetadataChunk(const std::string& metadata, MetadataId case mdIccProfile: break; case mdNone: - assert(false); + break; } return chunk; @@ -356,7 +352,6 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse arr.alloc(uncompressedLen); zlibResult = uncompress(arr.data(), &uncompressedLen, compressedText, compressedTextSize); if (zlibResult == Z_OK) { - assert((uLongf)arr.size() >= uncompressedLen); arr.resize(uncompressedLen); } else if (zlibResult == Z_BUF_ERROR) { // the uncompressedArray needs to be larger @@ -390,7 +385,6 @@ std::string PngChunk::zlibCompress(const std::string& text) { switch (zlibResult) { case Z_OK: - assert((uLongf)arr.size() >= compressedLen); arr.resize(compressedLen); break; case Z_BUF_ERROR: diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 4ba0fb80..9db99bd6 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -37,8 +37,8 @@ constexpr unsigned char pngBlank[] = { const auto nullComp = reinterpret_cast("\0\0"); const auto typeICCP = reinterpret_cast("iCCP"); +/// \todo use string_view and remove the last parameter inline bool compare(const char* str, const Exiv2::DataBuf& buf, size_t length) { - assert(strlen(str) <= length); const auto minlen = std::min(length, buf.size()); return buf.cmpBytes(0, str, minlen) == 0; } diff --git a/src/tags.cpp b/src/tags.cpp index f78da1bc..679ee9fa 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -233,8 +233,6 @@ void ExifKey::Impl::decomposeKey(const std::string& key) { } void ExifKey::Impl::makeKey(uint16_t tag, IfdId ifdId, const TagInfo* tagInfo) { - assert(tagInfo); - tagInfo_ = tagInfo; tag_ = tag; ifdId_ = ifdId; diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 6cb9ab96..6f77f8f0 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -79,7 +79,6 @@ TiffIfdMakernote::TiffIfdMakernote(uint16_t tag, IfdId group, IfdId mnGroup, MnH TiffBinaryArray::TiffBinaryArray(uint16_t tag, IfdId group, const ArrayCfg* arrayCfg, const ArrayDef* arrayDef, int defSize) : TiffEntryBase(tag, group, arrayCfg->elTiffType_), arrayCfg_(arrayCfg), arrayDef_(arrayDef), defSize_(defSize) { - assert(arrayCfg); } TiffBinaryArray::TiffBinaryArray(uint16_t tag, IfdId group, const ArraySet* arraySet, int setSize, @@ -89,8 +88,6 @@ TiffBinaryArray::TiffBinaryArray(uint16_t tag, IfdId group, const ArraySet* arra arraySet_(arraySet), setSize_(setSize) { // We'll figure out the correct cfg later - assert(cfgSelFct); - assert(arraySet_); } TiffBinaryElement::TiffBinaryElement(uint16_t tag, IfdId group) : @@ -191,12 +188,10 @@ TiffSubIfd* TiffSubIfd::doClone() const { } TiffMnEntry* TiffMnEntry::doClone() const { - assert(false); // Not implemented return nullptr; } TiffIfdMakernote* TiffIfdMakernote::doClone() const { - assert(false); // Not implemented return nullptr; } @@ -341,7 +336,6 @@ size_t TiffIfdMakernote::ifdOffset() const { } ByteOrder TiffIfdMakernote::byteOrder() const { - assert(imageByteOrder_ != invalidByteOrder); if (!pHeader_ || pHeader_->byteOrder() == invalidByteOrder) { return imageByteOrder_; } @@ -420,8 +414,6 @@ void TiffBinaryArray::iniOrigDataBuf() { } bool TiffBinaryArray::updOrigDataBuf(const byte* pData, size_t size) { - assert(pData); - if (origSize_ != size) return false; if (origData_ == pData) @@ -437,7 +429,6 @@ uint32_t TiffBinaryArray::addElement(uint32_t idx, const ArrayDef& def) { auto tp = dynamic_cast(tc.get()); // The assertion typically fails if a component is not configured in // the TIFF structure table (TiffCreator::tiffTreeStruct_) - assert(tp); tp->setStart(pData() + idx); tp->setData(const_cast(pData() + idx), sz, storage()); tp->setElDef(def); @@ -458,7 +449,6 @@ TiffComponent* TiffComponent::doAddPath(uint16_t /*tag*/, TiffPath& /*tiffPath*/ TiffComponent* TiffDirectory::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffComponent* const pRoot, TiffComponent::UniquePtr object) { - assert(tiffPath.size() > 1); tiffPath.pop(); const TiffPathItem tpi = tiffPath.top(); @@ -486,7 +476,6 @@ TiffComponent* TiffDirectory::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffCo } else { atc = TiffCreator::create(tpi.extendedTag(), tpi.group()); } - assert(atc); // Prevent dangling sub-IFD tags: Do not add a sub-IFD component without children. // Todo: How to check before creating the component? @@ -504,7 +493,6 @@ TiffComponent* TiffDirectory::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffCo TiffComponent* TiffSubIfd::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffComponent* const pRoot, TiffComponent::UniquePtr object) { - assert(!tiffPath.empty()); const TiffPathItem tpi1 = tiffPath.top(); tiffPath.pop(); if (tiffPath.empty()) { @@ -535,7 +523,6 @@ TiffComponent* TiffSubIfd::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffCompo TiffComponent* TiffMnEntry::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffComponent* const pRoot, TiffComponent::UniquePtr object) { - assert(!tiffPath.empty()); const TiffPathItem tpi1 = tiffPath.top(); tiffPath.pop(); if (tiffPath.empty()) { @@ -547,7 +534,6 @@ TiffComponent* TiffMnEntry::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffComp if (!mn_) { mnGroup_ = tpi2.group(); mn_ = TiffMnCreator::create(tpi1.tag(), tpi1.group(), mnGroup_); - assert(mn_); } return mn_->addPath(tag, tiffPath, pRoot, std::move(object)); } // TiffMnEntry::doAddPath @@ -587,8 +573,6 @@ TiffComponent* TiffBinaryArray::doAddPath(uint16_t tag, TiffPath& tiffPath, Tiff } else { atc = TiffCreator::create(tpi.extendedTag(), tpi.group()); } - assert(atc); - assert(tpi.extendedTag() != Tag::next); tc = addChild(std::move(atc)); setCount(elements_.size()); } @@ -611,7 +595,6 @@ TiffComponent* TiffDirectory::doAddChild(TiffComponent::UniquePtr tiffComponent) TiffComponent* TiffSubIfd::doAddChild(TiffComponent::UniquePtr tiffComponent) { auto d = dynamic_cast(tiffComponent.release()); - assert(d); ifds_.push_back(d); return d; } // TiffSubIfd::doAddChild @@ -926,7 +909,6 @@ uint32_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64 ioWrapper.write(buf, 4); idx += 4; } - assert(idx == sizeDir); // 2nd: Write IFD values - may contain pointers to additional data valueIdx = static_cast(sizeDir); @@ -947,7 +929,6 @@ uint32_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64 sd += sd & 1; // Align data to word boundary dataIdx += sd; } - assert(idx == sizeDir + sizeValue); // 3rd: Write data - may contain offsets too (eg sub-IFD) dataIdx = static_cast(sizeDir + sizeValue); @@ -969,9 +950,7 @@ uint32_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64 uint32_t TiffDirectory::writeDirEntry(IoWrapper& ioWrapper, ByteOrder byteOrder, int64_t offset, TiffComponent* pTiffComponent, uint32_t valueIdx, uint32_t dataIdx, uint32_t& imageIdx) { - assert(pTiffComponent); auto pDirEntry = dynamic_cast(pTiffComponent); - assert(pDirEntry); byte buf[8]; us2Data(buf, pDirEntry->tag(), byteOrder); us2Data(buf + 2, pDirEntry->tiffType(), byteOrder); @@ -1122,7 +1101,7 @@ uint32_t TiffBinaryArray::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int idx += ul2Data(buf, static_cast(size()), byteOrder); break; default: - assert(false); + break; } mioWrapper.write(buf, elSize); } @@ -1229,9 +1208,8 @@ uint32_t TiffSubIfd::doWriteData(IoWrapper& ioWrapper, ByteOrder byteOrder, int6 uint32_t TiffIfdMakernote::doWriteData(IoWrapper& /*ioWrapper*/, ByteOrder /*byteOrder*/, int64_t /*offset*/, uint32_t /*dataIdx*/, uint32_t& /*imageIdx*/) const { - assert(false); return 0; -} // TiffIfdMakernote::doWriteData +} uint32_t TiffComponent::writeImage(IoWrapper& ioWrapper, ByteOrder byteOrder) const { return doWriteImage(ioWrapper, byteOrder); @@ -1413,7 +1391,6 @@ size_t TiffComponent::sizeData() const { } size_t TiffDirectory::doSizeData() const { - assert(false); return 0; } @@ -1445,7 +1422,6 @@ size_t TiffSubIfd::doSizeData() const { } size_t TiffIfdMakernote::doSizeData() const { - assert(false); return 0; } @@ -1537,16 +1513,12 @@ TiffType toTiffType(TypeId typeId) { } bool cmpTagLt(TiffComponent const* lhs, TiffComponent const* rhs) { - assert(lhs); - assert(rhs); if (lhs->tag() != rhs->tag()) return lhs->tag() < rhs->tag(); return lhs->idx() < rhs->idx(); } bool cmpGroupLt(TiffComponent const* lhs, TiffComponent const* rhs) { - assert(lhs); - assert(rhs); return lhs->group() < rhs->group(); } diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index acb42c0e..24c427a2 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1832,7 +1832,6 @@ void TiffCreator::getPath(TiffPath& tiffPath, uint32_t extendedTag, IfdId group, do { tiffPath.push(TiffPathItem(extendedTag, group)); ts = find(tiffTreeStruct_, TiffTreeStruct::Key(root, group)); - assert(ts); extendedTag = ts->parentExtTag_; group = ts->parentGroup_; } while (!(ts->root_ == root && ts->group_ == ifdIdNotSet)); @@ -1867,8 +1866,6 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size writing"). If there is a parsed tree, it is only used to access the image data in this case. */ - assert(pHeader); - assert(pHeader->byteOrder() != invalidByteOrder); WriteMethod writeMethod = wmIntrusive; auto parsedTree = parse(pData, size, root, pHeader); PrimaryGroups primaryGroups; @@ -1985,7 +1982,6 @@ DataBuf TiffHeaderBase::write() const { buf.write_uint8(0, 'M'); break; case invalidByteOrder: - assert(false); break; } buf.write_uint8(1, buf.read_uint8(0)); diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 7d3ab2f0..79eb3dc5 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -54,12 +54,10 @@ TiffVisitor::TiffVisitor() { } void TiffVisitor::setGo(GoEvent event, bool go) { - assert(event >= 0 && static_cast(event) < events_); go_[event] = go; } bool TiffVisitor::go(GoEvent event) const { - assert(event >= 0 && static_cast(event) < events_); return go_[event]; } @@ -132,14 +130,9 @@ void TiffFinder::visitBinaryElement(TiffBinaryElement* object) { TiffCopier::TiffCopier(TiffComponent* pRoot, uint32_t root, const TiffHeaderBase* pHeader, const PrimaryGroups* pPrimaryGroups) : pRoot_(pRoot), root_(root), pHeader_(pHeader), pPrimaryGroups_(pPrimaryGroups) { - assert(pRoot_); - assert(pHeader_); - assert(pPrimaryGroups_); } void TiffCopier::copyObject(TiffComponent* object) { - assert(object); - if (pHeader_->isImageTag(object->tag(), object->group(), pPrimaryGroups_)) { auto clone = object->clone(); // Assumption is that the corresponding TIFF entry doesn't exist @@ -201,8 +194,6 @@ TiffDecoder::TiffDecoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpDat pRoot_(pRoot), findDecoderFct_(findDecoderFct), decodedIptc_(false) { - assert(pRoot); - // #1402 Fujifilm RAF. Search for the make // Find camera make in existing metadata (read from the JPEG) ExifKey key("Exif.Image.Make"); @@ -249,8 +240,6 @@ void TiffDecoder::visitMnEntry(TiffMnEntry* object) { } void TiffDecoder::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object); - exifData_["Exif.MakerNote.Offset"] = object->mnOffset(); switch (object->byteOrder()) { case littleEndian: @@ -260,7 +249,6 @@ void TiffDecoder::visitIfdMakernote(TiffIfdMakernote* object) { exifData_["Exif.MakerNote.ByteOrder"] = "MM"; break; case invalidByteOrder: - assert(object->byteOrder() != invalidByteOrder); break; } } @@ -434,8 +422,6 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) { } void TiffDecoder::decodeTiffEntry(const TiffEntryBase* object) { - assert(object); - // Don't decode the entry if value is not set if (!object->pValue()) return; @@ -448,7 +434,6 @@ void TiffDecoder::decodeTiffEntry(const TiffEntryBase* object) { } // TiffDecoder::decodeTiffEntry void TiffDecoder::decodeStdTiffEntry(const TiffEntryBase* object) { - assert(object); ExifKey key(object->tag(), groupName(object->group())); key.setIdx(object->idx()); exifData_.add(key, object->pValue()); @@ -480,10 +465,6 @@ TiffEncoder::TiffEncoder(ExifData exifData, const IptcData& iptcData, const XmpD findEncoderFct_(findEncoderFct), dirty_(false), writeMethod_(wmNonIntrusive) { - assert(pRoot); - assert(pPrimaryGroups); - assert(pHeader); - byteOrder_ = pHeader->byteOrder(); origByteOrder_ = byteOrder_; @@ -616,8 +597,6 @@ void TiffEncoder::visitDirectory(TiffDirectory* /*object*/) { void TiffEncoder::visitDirectoryNext(TiffDirectory* object) { // Update type and count in IFD entries, in case they changed - assert(object); - byte* p = object->start() + 2; for (auto&& component : object->components_) { p += updateDirEntry(p, byteOrder(), component); @@ -625,10 +604,7 @@ void TiffEncoder::visitDirectoryNext(TiffDirectory* object) { } uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffComponent* pTiffComponent) { - assert(buf); - assert(pTiffComponent); auto pTiffEntry = dynamic_cast(pTiffComponent); - assert(pTiffEntry); us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder); ul2Data(buf + 4, static_cast(pTiffEntry->count()), byteOrder); // Move data to offset field, if it fits and is not yet there. @@ -663,8 +639,6 @@ void TiffEncoder::visitMnEntry(TiffMnEntry* object) { } void TiffEncoder::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object); - auto pos = exifData_.findKey(ExifKey("Exif.MakerNote.ByteOrder")); if (pos != exifData_.end()) { // Set Makernote byte order @@ -705,8 +679,6 @@ void TiffEncoder::visitBinaryArray(TiffBinaryArray* object) { } void TiffEncoder::visitBinaryArrayEnd(TiffBinaryArray* object) { - assert(object); - if (!object->cfg() || !object->decoded()) return; size_t size = object->TiffEntryBase::doSize(); @@ -747,8 +719,6 @@ bool TiffEncoder::isImageTag(uint16_t tag, IfdId group) const { } void TiffEncoder::encodeTiffComponent(TiffEntryBase* object, const Exifdatum* datum) { - assert(object); - auto pos = exifData_.end(); const Exifdatum* ed = datum; if (!ed) { @@ -809,8 +779,6 @@ void TiffEncoder::encodeDataEntry(TiffDataEntry* object, const Exifdatum* datum) encodeOffsetEntry(object, datum); if (!dirty_ && writeMethod() == wmNonIntrusive) { - assert(object); - assert(object->pValue()); if (object->sizeDataArea_ < static_cast(object->pValue()->sizeDataArea())) { #ifdef EXIV2_DEBUG_MESSAGES ExifKey key(object->tag(), groupName(object->group())); @@ -922,9 +890,6 @@ void TiffEncoder::encodeSubIfd(TiffSubIfd* object, const Exifdatum* datum) { } // TiffEncoder::encodeSubIfd void TiffEncoder::encodeTiffEntryBase(TiffEntryBase* object, const Exifdatum* datum) { - assert(object); - assert(datum); - #ifdef EXIV2_DEBUG_MESSAGES bool tooLarge = false; #endif @@ -946,9 +911,6 @@ void TiffEncoder::encodeTiffEntryBase(TiffEntryBase* object, const Exifdatum* da } void TiffEncoder::encodeOffsetEntry(TiffEntryBase* object, const Exifdatum* datum) { - assert(object); - assert(datum); - size_t newSize = datum->size(); if (newSize > object->size_) { // value doesn't fit, encode for intrusive writing setDirty(); @@ -969,8 +931,6 @@ void TiffEncoder::encodeOffsetEntry(TiffEntryBase* object, const Exifdatum* datu } void TiffEncoder::add(TiffComponent* pRootDir, TiffComponent* pSourceDir, uint32_t root) { - assert(pRootDir); - writeMethod_ = wmIntrusive; pSourceTree_ = pSourceDir; @@ -1044,8 +1004,6 @@ TiffReader::TiffReader(const byte* pData, size_t size, TiffComponent* pRoot, Tif mnState_(state), postProc_(false) { pState_ = &origState_; - assert(pData_); - assert(size_); } // TiffReader::TiffReader @@ -1066,18 +1024,14 @@ void TiffReader::setMnState(const TiffRwState* state) { } ByteOrder TiffReader::byteOrder() const { - assert(pState_); return pState_->byteOrder(); } uint32_t TiffReader::baseOffset() const { - assert(pState_); return pState_->baseOffset(); } void TiffReader::readDataEntryBase(TiffDataEntryBase* object) { - assert(object); - readTiffEntry(object); TiffFinder finder(object->szTag(), object->szGroup()); pRoot_->accept(finder); @@ -1100,8 +1054,6 @@ void TiffReader::visitImageEntry(TiffImageEntry* object) { } void TiffReader::visitSizeEntry(TiffSizeEntry* object) { - assert(object); - readTiffEntry(object); TiffFinder finder(object->dtTag(), object->dtGroup()); pRoot_->accept(finder); @@ -1139,10 +1091,7 @@ void TiffReader::postProcess() { } void TiffReader::visitDirectory(TiffDirectory* object) { - assert(object); - const byte* p = object->start(); - assert(p >= pData_); if (circularReference(object->start(), object->group())) return; @@ -1217,8 +1166,6 @@ void TiffReader::visitDirectory(TiffDirectory* object) { } // TiffReader::visitDirectory void TiffReader::visitSubIfd(TiffSubIfd* object) { - assert(object); - readTiffEntry(object); if ((object->tiffType() == ttUnsignedLong || object->tiffType() == ttSignedLong || object->tiffType() == ttTiffIfd) && object->count() >= 1) { @@ -1258,8 +1205,6 @@ void TiffReader::visitSubIfd(TiffSubIfd* object) { } // TiffReader::visitSubIfd void TiffReader::visitMnEntry(TiffMnEntry* object) { - assert(object); - readTiffEntry(object); // Find camera make TiffFinder finder(0x010f, ifd0Id); @@ -1278,8 +1223,6 @@ void TiffReader::visitMnEntry(TiffMnEntry* object) { } // TiffReader::visitMnEntry void TiffReader::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object); - object->setImageByteOrder(byteOrder()); // set the byte order for the image if (!object->readHeader(object->start(), static_cast(pLast_ - object->start()), byteOrder())) { @@ -1310,10 +1253,7 @@ void TiffReader::visitIfdMakernoteEnd(TiffIfdMakernote* /*object*/) { } // TiffReader::visitIfdMakernoteEnd void TiffReader::readTiffEntry(TiffEntryBase* object) { - assert(object); - byte* p = object->start(); - assert(p >= pData_); if (p + 12 > pLast_) { #ifndef SUPPRESS_WARNINGS @@ -1421,8 +1361,6 @@ void TiffReader::readTiffEntry(TiffEntryBase* object) { } // TiffReader::readTiffEntry void TiffReader::visitBinaryArray(TiffBinaryArray* object) { - assert(object); - if (!postProc_) { // Defer reading children until after all other components are read, but // since state (offset) is not set during post-processing, read entry here diff --git a/src/types.cpp b/src/types.cpp index 1b04c224..26c0ca8f 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -10,7 +10,6 @@ // + standard includes #include -#include #include #include #include @@ -331,7 +330,6 @@ float getFloat(const byte* buf, ByteOrder byteOrder) { // This algorithm assumes that the internal representation of the float // type is the 4-byte IEEE 754 binary32 format, which is common but not // required by the C++ standard. - assert(sizeof(float) == 4); union { uint32_t ul_; float f_; @@ -344,7 +342,6 @@ double getDouble(const byte* buf, ByteOrder byteOrder) { // This algorithm assumes that the internal representation of the double // type is the 8-byte IEEE 754 binary64 format, which is common but not // required by the C++ standard. - assert(sizeof(double) == 8); union { uint64_t ull_; double d_; @@ -447,7 +444,6 @@ long f2Data(byte* buf, float f, ByteOrder byteOrder) { // This algorithm assumes that the internal representation of the float // type is the 4-byte IEEE 754 binary32 format, which is common but not // required by the C++ standard. - assert(sizeof(float) == 4); union { uint32_t ul_; float f_; @@ -460,7 +456,6 @@ long d2Data(byte* buf, double d, ByteOrder byteOrder) { // This algorithm assumes that the internal representation of the double // type is the 8-byte IEEE 754 binary64 format, which is common but not // required by the C++ standard. - assert(sizeof(double) == 8); union { uint64_t ull_; double d_; @@ -524,8 +519,6 @@ bool isHex(const std::string& str, size_t size, const std::string& prefix) { } // isHex int exifTime(const char* buf, struct tm* tm) { - assert(buf); - assert(tm); int rc = 1; int year = 0, mon = 0, mday = 0, hour = 0, min = 0, sec = 0; int scanned = std::sscanf(buf, "%4d:%2d:%2d %2d:%2d:%2d", &year, &mon, &mday, &hour, &min, &sec); diff --git a/src/value.cpp b/src/value.cpp index 7f145156..5184c042 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -9,7 +9,6 @@ #include "types.hpp" // + standard includes - #include #include @@ -223,7 +222,6 @@ size_t StringValueBase::copy(byte* buf, ByteOrder /*byteOrder*/) const { if (value_.empty()) return 0; // byteOrder not needed - assert(buf); return value_.copy(reinterpret_cast(buf), value_.size()); } @@ -381,16 +379,13 @@ size_t CommentValue::copy(byte* buf, ByteOrder byteOrder) const { [[maybe_unused]] const size_t sz = c.size(); if (byteOrder_ == littleEndian && byteOrder == bigEndian) { convertStringCharset(c, "UCS-2LE", "UCS-2BE"); - assert(c.size() == sz); } else if (byteOrder_ == bigEndian && byteOrder == littleEndian) { convertStringCharset(c, "UCS-2BE", "UCS-2LE"); - assert(c.size() == sz); } c = value_.substr(0, 8) + c; } if (c.empty()) return 0; - assert(buf); return c.copy(reinterpret_cast(buf), c.size()); } @@ -849,7 +844,6 @@ size_t DateValue::copy(byte* buf, ByteOrder /*byteOrder*/) const { // sprintf wants to add the null terminator, so use oversized buffer char temp[9]; size_t wrote = static_cast(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day)); - assert(wrote == 8); std::memcpy(buf, temp, wrote); return wrote; }