From 7e382e72444e9fbf4e706abb58ffc9d28dbc5b16 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 16 Jul 2023 17:43:05 -0700 Subject: [PATCH] coverity fixes Signed-off-by: Rosen Penev (cherry picked from commit d4f6c9cf40a80dc11c536d5c8399c49a1b9e62cb) --- samples/geotag.cpp | 9 +-------- src/basicio.cpp | 5 +---- src/image.cpp | 4 +--- src/value.cpp | 2 +- src/xmp.cpp | 1 - 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/samples/geotag.cpp b/samples/geotag.cpp index 00f01a83f0..d0df9459d7 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -419,13 +419,6 @@ std::string makePath(const std::string& dir, const std::string& file) { return dir + std::string(EXV_SEPARATOR_STR) + file; } -const char* makePath(const char* dir, const char* file) { - static char result[_MAX_PATH]; - std::string r = makePath(std::string(dir), std::string(file)); - strcpy(result, r.c_str()); - return result; -} - // file utilities bool readDir(const char* path, Options& options) { bool bResult = false; @@ -451,7 +444,7 @@ bool readDir(const char* path, Options& options) { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // _tprintf(TEXT(" %s \n"), ffd.cFileName); } else { - std::string pathName = makePath(path, std::string(ffd.cFileName)); + std::string pathName = makePath(path, ffd.cFileName); if (getFileType(pathName, options) == typeImage) { gFiles.push_back(pathName); } diff --git a/src/basicio.cpp b/src/basicio.cpp index a743c8ce1e..6b99509e91 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -167,10 +167,7 @@ int FileIo::Impl::switchMode(OpMode opMode) { if (offset == -1) return -1; // 'Manual' open("r+b") to avoid munmap() - if (fp_) { - std::fclose(fp_); - fp_ = nullptr; - } + std::fclose(fp_); openMode_ = "r+b"; opMode_ = opSeek; fp_ = std::fopen(path_.c_str(), openMode_.c_str()); diff --git a/src/image.cpp b/src/image.cpp index 749fd3b572..b9752c47e9 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -770,7 +770,7 @@ ImageType ImageFactory::getType(BasicIo& io) { return ImageType::none; } -BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, bool useCurl) { +BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, [[maybe_unused]] bool useCurl) { Protocol fProt = fileProtocol(path); #ifdef EXV_USE_CURL @@ -789,8 +789,6 @@ BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, bool useCurl) return std::make_unique(path); // may throw return std::make_unique(path); - - (void)(useCurl); } // ImageFactory::createIo Image::UniquePtr ImageFactory::open(const std::string& path, bool useCurl) { diff --git a/src/value.cpp b/src/value.cpp index f85ff434d4..b2ca8b7c9b 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -370,7 +370,7 @@ std::string CommentValue::comment(const char* encoding) const { if (charsetId() == unicode) { const char* from = !encoding || *encoding == '\0' ? detectCharset(c) : encoding; if (!convertStringCharset(c, from, "UTF-8")) - throw Error(ErrorCode::kerInvalidIconvEncoding, encoding, "UTF-8"); + throw Error(ErrorCode::kerInvalidIconvEncoding, from, "UTF-8"); } // # 1266 Remove trailing nulls diff --git a/src/xmp.cpp b/src/xmp.cpp index 99c8103d8b..4a7f4312d5 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -693,7 +693,6 @@ int XmpParser::decode(XmpData& xmpData, const std::string& xmpPacket) { printNode(schemaNs, propPath, propValue, opt); if (XMP_PropIsAlias(opt)) { throw Error(ErrorCode::kerAliasesNotSupported, schemaNs, propPath, propValue); - continue; } if (XMP_NodeIsSchema(opt)) { // Register unknown namespaces with Exiv2