diff --git a/src/iptc.cpp b/src/iptc.cpp index 4bccaea75a..3aeadbddcd 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -420,10 +420,11 @@ int IptcParser::decode(IptcData& iptcData, const byte* pData, size_t size) { } // IptcParser::decode DataBuf IptcParser::encode(const IptcData& iptcData) { + DataBuf buf; if (iptcData.empty()) - return {}; + return buf; - DataBuf buf(iptcData.size()); + buf = DataBuf(iptcData.size()); byte* pWrite = buf.data(); // Copy the iptc data sets and sort them by record but preserve the order of datasets diff --git a/src/jp2image.cpp b/src/jp2image.cpp index fd0ea16800..7b4309a867 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -100,9 +100,9 @@ Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, m // Obtains the ascii version from the box.type std::string Jp2Image::toAscii(uint32_t n) { const auto p = reinterpret_cast(&n); - if (isBigEndianPlatform()) - return std::string(p, p + 4); std::string result(p, p + 4); + if (isBigEndianPlatform()) + return result; std::reverse(result.begin(), result.end()); return result; } diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 1b38829bc2..82ae6d4161 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -467,11 +467,11 @@ std::string PngChunk::makeUtf8TxtChunk(const std::string& keyword, const std::st } // PngChunk::makeUtf8TxtChunk DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) { + DataBuf info; if (text.size() <= 1) { - return {}; + return info; } - DataBuf info; const unsigned char unhex[103] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -488,26 +488,26 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) { const char* eot = text.c_str(text.size() - 1); // end of text if (sp >= eot) { - return {}; + return info; } // Look for newline while (*sp != '\n') { sp++; if (sp == eot) { - return {}; + return info; } } sp++; // step over '\n' if (sp == eot) { - return {}; + return info; } // Look for length while (*sp == '\0' || *sp == ' ' || *sp == '\n') { sp++; if (sp == eot) { - return {}; + return info; } } @@ -519,12 +519,12 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) { length = newlength; sp++; if (sp == eot) { - return {}; + return info; } } sp++; // step over '\n' if (sp == eot) { - return {}; + return info; } enforce(length <= static_cast(eot - sp) / 2, Exiv2::ErrorCode::kerCorruptedMetadata); @@ -540,7 +540,7 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: cannot allocate memory\n"; #endif - return {}; + return info; } if (info.empty()) // Early return diff --git a/src/preview.cpp b/src/preview.cpp index 21ae651ec3..a429c86225 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -325,16 +325,16 @@ const LoaderTiff::Param LoaderTiff::param_[] = { }; Loader::UniquePtr Loader::create(PreviewId id, const Image& image) { + Loader::UniquePtr loader; if (id < 0 || id >= Loader::getNumLoaders()) - return nullptr; + return loader; if (loaderList_[id].imageMimeType_ && std::string(loaderList_[id].imageMimeType_) != image.mimeType()) - return nullptr; + return loader; - auto loader = loaderList_[id].create_(id, image, loaderList_[id].parIdx_); - - if (loader && !loader->valid()) - return nullptr; + loader = loaderList_[id].create_(id, image, loaderList_[id].parIdx_); + if (!loader->valid()) + loader = nullptr; return loader; } @@ -568,11 +568,13 @@ PreviewProperties LoaderExifDataJpeg::getProperties() const { } DataBuf LoaderExifDataJpeg::getData() const { + DataBuf buf; + if (!valid()) - return {}; + return buf; if (auto pos = image_.exifData().findKey(dataKey_); pos != image_.exifData().end()) { - DataBuf buf = pos->dataArea(); // indirect data + buf = pos->dataArea(); // indirect data if (buf.empty()) { // direct data buf = DataBuf(pos->size()); @@ -583,7 +585,7 @@ DataBuf LoaderExifDataJpeg::getData() const { return buf; } - return {}; + return buf; } bool LoaderExifDataJpeg::readDimensions() { @@ -854,6 +856,7 @@ DataBuf decodeHex(const byte* src, size_t srcSize) { const char encodeBase64Table[64 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; DataBuf decodeBase64(const std::string& src) { + DataBuf dest; // create decoding table unsigned long invalid = 64; auto decodeBase64Table = std::vector(256, invalid); @@ -864,11 +867,11 @@ DataBuf decodeBase64(const std::string& src) { auto validSrcSize = static_cast( std::count_if(src.begin(), src.end(), [&](unsigned char c) { return decodeBase64Table.at(c) != invalid; })); if (validSrcSize > ULONG_MAX / 3) - return {}; // avoid integer overflow + return dest; // avoid integer overflow const unsigned long destSize = (validSrcSize * 3) / 4; // allocate dest buffer - DataBuf dest(destSize); + dest = DataBuf(destSize); // decode for (unsigned long srcPos = 0, destPos = 0; destPos < destSize;) { @@ -930,18 +933,19 @@ DataBuf decodeAi7Thumbnail(const DataBuf& src) { } DataBuf makePnm(size_t width, size_t height, const DataBuf& rgb) { + DataBuf dest; if (size_t expectedSize = width * height * 3UL; rgb.size() != expectedSize) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Invalid size of preview data. Expected " << expectedSize << " bytes, got " << rgb.size() << " bytes.\n"; #endif - return {}; + return dest; } const std::string header = "P6\n" + std::to_string(width) + " " + std::to_string(height) + "\n255\n"; const auto headerBytes = reinterpret_cast(header.data()); - DataBuf dest(header.size() + rgb.size()); + dest = DataBuf(header.size() + rgb.size()); std::copy_n(headerBytes, header.size(), dest.begin()); std::copy_n(rgb.c_data(), rgb.size(), dest.begin() + header.size()); return dest; diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index c5d86cf87f..d67f172d2f 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -2101,12 +2101,13 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size TiffComponent::UniquePtr TiffParserWorker::parse(const byte* pData, size_t size, uint32_t root, TiffHeaderBase* pHeader) { + TiffComponent::UniquePtr rootDir; if (!pData || size == 0) - return nullptr; + return rootDir; if (!pHeader->read(pData, size) || pHeader->offset() >= size) { throw Error(ErrorCode::kerNotAnImage, "TIFF"); } - auto rootDir = TiffCreator::create(root, IfdId::ifdIdNotSet); + rootDir = TiffCreator::create(root, IfdId::ifdIdNotSet); if (rootDir) { rootDir->setStart(pData + pHeader->offset()); auto state = TiffRwState{pHeader->byteOrder(), 0};