From d4f6c9cf40a80dc11c536d5c8399c49a1b9e62cb 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 --- 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 9c6581ffe8..7ad726fea4 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -420,13 +420,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; @@ -452,7 +445,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 e3532a0ff2..dcd64ca137 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 bfe1e1a53b..358da7e835 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -786,7 +786,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 @@ -803,8 +803,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 24f2786e44..6b8d1d75e2 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -371,7 +371,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 a517f78e7a..5130ca6c31 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