Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverity fixes #2513

Merged
merged 9 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,8 +1676,7 @@ std::string temporaryPath() {
auto guard = std::scoped_lock(cs);

#if defined(_WIN32)
HANDLE process = nullptr;
DWORD pid = ::GetProcessId(process);
DWORD pid = ::GetCurrentProcessId();
#else
pid_t pid = ::getpid();
#endif
Expand Down
6 changes: 1 addition & 5 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,9 @@ int main(int argc, char* const argv[]) {

Params::Params() :
optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:K:n:Q:"),

target_(ctExif | ctIptc | ctComment | ctXmp),

yodAdjust_(emptyYodAdjust_),
format_("%Y%m%d_%H%M%S") {
yodAdjust_[yodYear] = emptyYodAdjust_[yodYear];
yodAdjust_[yodMonth] = emptyYodAdjust_[yodMonth];
yodAdjust_[yodDay] = emptyYodAdjust_[yodDay];
}

Params& Params::instance() {
Expand Down
7 changes: 4 additions & 3 deletions include/exiv2/asfvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class EXIV2API AsfVideo : public Image {

class HeaderReader {
DataBuf IdBuf_;
uint64_t size_;
uint64_t remaining_size_;
uint64_t size_{};
uint64_t remaining_size_{};

public:
explicit HeaderReader(BasicIo::UniquePtr& io);
Expand Down Expand Up @@ -159,7 +159,8 @@ class EXIV2API AsfVideo : public Image {

private:
//! Variable to store height and width of a video frame.
uint64_t height_, width_;
uint64_t height_{};
uint64_t width_{};

}; // Class AsfVideo

Expand Down
8 changes: 4 additions & 4 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace Exiv2 {

//! Native preview information. This is meant to be used only by the PreviewManager.
struct NativePreview {
size_t position_; //!< Position
size_t size_; //!< Size
size_t width_; //!< Width
size_t height_; //!< Height
size_t position_{}; //!< Position
size_t size_{}; //!< Size
size_t width_{}; //!< Width
size_t height_{}; //!< Height
std::string filter_; //!< Filter
std::string mimeType_; //!< MIME type
};
Expand Down
35 changes: 16 additions & 19 deletions include/exiv2/matroskavideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ enum matroskaTypeEnum : char {
Master = 'm',
Float = 'f',
Utf8 = '8',
UndefinedType = 'z'

UndefinedType = 'z',
};

enum matroskaProcessEnum : char { Process = 'p', Skip = 's', Composite = 'c', Undefined = 'u' };
enum matroskaProcessEnum : char {
Process = 'p',
Skip = 's',
Composite = 'c',
Undefined = 'u',
};

struct MatroskaTag {
uint64_t _id;
Expand All @@ -72,6 +76,10 @@ struct MatroskaTag {
_process(matroskaProcessEnum::Undefined) {
}

bool operator==(uint64_t id) const {
return id == _id;
}

bool isSkipped() const {
return _process == Skip;
}
Expand All @@ -84,17 +92,6 @@ struct MatroskaTag {
<< "]\n";
}
};

/// @brief Utility function to search into std::array of pairs
/// @return the searched pair if exist,else nullptr
template <size_t N>
[[nodiscard]] const MatroskaTag* findTag(const std::array<MatroskaTag, N>& src, const uint64_t& key) {
const auto rc = std::find_if(src.begin(), src.end(), [&key](const MatroskaTag& tag) { return tag._id == key; });
// the return value is of type "const MatroskaTag*", so we return the adress of the content of the input
// iterator return by find_if
return rc == std::end(src) ? nullptr : &(*rc);
}

} // namespace Internal

/*!
Expand Down Expand Up @@ -161,13 +158,13 @@ class EXIV2API MatroskaVideo : public Image {

private:
//! Variable to check the end of metadata traversing.
bool continueTraversing_;
bool continueTraversing_{};
//! Variable to store height and width of a video frame.
uint64_t height_;
uint64_t width_;
uint32_t track_count_;
uint64_t height_{};
uint64_t width_{};
uint32_t track_count_{};
double time_code_scale_ = 1.0;
uint64_t stream_ = 0;
uint64_t stream_{};

static constexpr double bytesMB = 1048576;

Expand Down
10 changes: 4 additions & 6 deletions include/exiv2/metadatum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class EXIV2API Key {

//! @name Creators
//@{
Key() = default;
//! Destructor
virtual ~Key() = default;
//@}
Key(const Key&) = default;
//! @name Accessors
//@{
/*!
Expand Down Expand Up @@ -74,6 +72,8 @@ class EXIV2API Key {
//@}

protected:
Key() = default;
Key(const Key&) = default;
//! @name Manipulators
//@{
/*!
Expand Down Expand Up @@ -102,10 +102,6 @@ class EXIV2API Metadatum {
public:
//! @name Creators
//@{
//! Default Constructor
Metadatum() = default;
//! Copy constructor
Metadatum(const Metadatum&) = default;
//! Destructor
virtual ~Metadatum() = default;
//@}
Expand Down Expand Up @@ -258,6 +254,8 @@ class EXIV2API Metadatum {
//@}

protected:
Metadatum() = default;
Metadatum(const Metadatum&) = default;
//! @name Manipulators
//@{
/*!
Expand Down
8 changes: 4 additions & 4 deletions include/exiv2/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ using PreviewId = int;
struct EXIV2API PreviewProperties {
std::string mimeType_; //!< Preview image mime type.
std::string extension_; //!< Preview image extension.
size_t size_; //!< Preview image size in bytes.
size_t width_; //!< Preview image width in pixels or 0 for unknown width.
size_t height_; //!< Preview image height in pixels or 0 for unknown height.
PreviewId id_; //!< Identifies type of preview image.
size_t size_{}; //!< Preview image size in bytes.
size_t width_{}; //!< Preview image width in pixels or 0 for unknown width.
size_t height_{}; //!< Preview image height in pixels or 0 for unknown height.
PreviewId id_{}; //!< Identifies type of preview image.
};

//! Container type to hold all preview images metadata.
Expand Down
4 changes: 0 additions & 4 deletions include/exiv2/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@ struct EXIV2API XmpPropertyInfo {
struct EXIV2API XmpNsInfo {
//! For comparison with prefix
struct Prefix {
//! Constructor.
explicit Prefix(std::string prefix);
//! The prefix string.
std::string prefix_;
};
//! For comparison with namespace
struct Ns {
//! Constructor.
explicit Ns(std::string ns);
//! The namespace string
std::string ns_;
};
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/riffvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class EXIV2API RiffVideo : public Image {
static constexpr auto CHUNK_ID_VPRP = "VPRP";
static constexpr auto CHUNK_ID_IDX1 = "IDX1";

int streamType_;
int streamType_{};

}; // Class RiffVideo

Expand Down
28 changes: 9 additions & 19 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class EXIV2API Value {
//@{
//! Constructor, taking a type id to initialize the base class with
explicit Value(TypeId typeId);
Value(const Value&) = default;
//! Virtual destructor.
virtual ~Value() = default;
//@}
Expand Down Expand Up @@ -223,6 +222,7 @@ class EXIV2API Value {
static UniquePtr create(TypeId typeId);

protected:
Value(const Value&) = default;
/*!
@brief Assignment operator. Protected so that it can only be used
by subclasses but not directly.
Expand Down Expand Up @@ -322,10 +322,6 @@ class EXIV2API StringValueBase : public Value {
explicit StringValueBase(TypeId typeId);
//! Constructor for subclasses
StringValueBase(TypeId typeId, const std::string& buf);
//! Copy constructor
StringValueBase(const StringValueBase&) = default;
//! Virtual destructor.
~StringValueBase() override = default;
//@}

//! @name Manipulators
Expand Down Expand Up @@ -364,8 +360,6 @@ class EXIV2API StringValueBase : public Value {
//@}

protected:
//! Assignment operator.
StringValueBase& operator=(const StringValueBase&);
//! Internal virtual copy constructor.
StringValueBase* clone_() const override = 0;

Expand Down Expand Up @@ -471,8 +465,6 @@ class EXIV2API CommentValue : public StringValueBase {
enum CharsetId { ascii, jis, unicode, undefined, invalidCharsetId, lastCharsetId };
//! Information pertaining to the defined character sets
struct CharsetTable {
//! Constructor
constexpr CharsetTable(CharsetId charsetId, const char* name, const char* code);
CharsetId charsetId_; //!< Charset id
const char* name_; //!< Name of the charset
const char* code_; //!< Code of the charset
Expand Down Expand Up @@ -923,9 +915,9 @@ class EXIV2API DateValue : public Value {

//! Simple Date helper structure
struct EXIV2API Date {
int32_t year{0}; //!< Year
int32_t month{0}; //!< Month
int32_t day{0}; //!< Day
int32_t year; //!< Year
int32_t month; //!< Month
int32_t day; //!< Day
};

//! @name Manipulators
Expand Down Expand Up @@ -1014,13 +1006,11 @@ class EXIV2API TimeValue : public Value {

//! Simple Time helper structure
struct Time {
Time() = default;

int32_t hour{0}; //!< Hour
int32_t minute{0}; //!< Minute
int32_t second{0}; //!< Second
int32_t tzHour{0}; //!< Hours ahead or behind UTC
int32_t tzMinute{0}; //!< Minutes ahead or behind UTC
int32_t hour; //!< Hour
int32_t minute; //!< Minute
int32_t second; //!< Second
int32_t tzHour; //!< Hours ahead or behind UTC
int32_t tzMinute; //!< Minutes ahead or behind UTC
};

//! @name Manipulators
Expand Down
1 change: 0 additions & 1 deletion src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class FileIo::Impl {
// TYPES
//! Simple struct stat wrapper for internal use
struct StructStat {
StructStat() = default;
mode_t st_mode{0}; //!< Permissions
off_t st_size{0}; //!< Size
};
Expand Down
2 changes: 1 addition & 1 deletion src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void IptcDataSets::dataSetList(std::ostream& os) {
}
}

IptcKey::IptcKey(std::string key) : key_(std::move(key)) {
IptcKey::IptcKey(std::string key) : tag_(0), record_(0), key_(std::move(key)) {
decomposeKey();
}

Expand Down
9 changes: 7 additions & 2 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
////////////////////////////////////
// and connect
server = connect(sockfd, reinterpret_cast<const struct sockaddr*>(&serv_addr), serv_len);
if (server == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
if (server == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(sockfd);
return error(errors, "error - unable to connect to server = %s port = %s wsa_error = %d", servername_p, port_p,
WSAGetLastError());
}

char buffer[32 * 1024 + 1];
size_t buff_l = sizeof buffer - 1;
Expand All @@ -248,9 +250,11 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
sleep_ -= snooze;
}

if (sleep_ < std::chrono::milliseconds::zero())
if (sleep_ < std::chrono::milliseconds::zero()) {
closesocket(sockfd);
return error(errors, "error - timeout connecting to server = %s port = %s wsa_error = %d", servername, port,
WSAGetLastError());
}

int end = 0; // write position in buffer
bool bSearching = true; // looking for headers in the response
Expand Down Expand Up @@ -344,6 +348,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
// we finished OK without finding headers, flush the buffer
flushBuffer(buffer, 0, end, file);
} else {
closesocket(sockfd);
return error(errors, "error - no response from server = %s port = %s wsa_error = %d", servername, port,
WSAGetLastError());
}
Expand Down
Loading