Skip to content

Commit

Permalink
Merge pull request #4097 from UB-Mannheim/main
Browse files Browse the repository at this point in the history
Fix some issues which were reported by Coverity Scan
  • Loading branch information
zdenop authored Jul 12, 2023
2 parents 82c7999 + 8df11a6 commit b86afd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/ccstruct/normalis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ DENORM::DENORM() {

DENORM::DENORM(const DENORM &src) {
rotation_ = nullptr;
x_map_ = nullptr;
y_map_ = nullptr;
*this = src;
}

Expand Down
12 changes: 6 additions & 6 deletions src/ccutil/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class GenericVector {

// Add a callback to be called to delete the elements when the array took
// their ownership.
void set_clear_callback(std::function<void(T)> cb) {
void set_clear_callback(const std::function<void(T)> &cb) {
clear_cb_ = cb;
}

Expand All @@ -148,8 +148,8 @@ class GenericVector {
// fread (and swapping)/fwrite.
// Returns false on error or if the callback returns false.
// DEPRECATED. Use [De]Serialize[Classes] instead.
bool write(FILE *f, std::function<bool(FILE *, const T &)> cb) const;
bool read(TFile *f, std::function<bool(TFile *, T *)> cb);
bool write(FILE *f, const std::function<bool(FILE *, const T &)> &cb) const;
bool read(TFile *f, const std::function<bool(TFile *, T *)> &cb);
// Writes a vector of simple types to the given file. Assumes that bitwise
// read/write of T will work. Returns false in case of error.
// TODO(rays) Change all callers to use TFile and remove deprecated methods.
Expand Down Expand Up @@ -577,7 +577,7 @@ int GenericVector<T>::push_back(T object) {
double_the_size();
}
index = size_used_++;
data_[index] = object;
data_[index] = std::move(object);
return index;
}

Expand Down Expand Up @@ -627,7 +627,7 @@ void GenericVector<T>::delete_data_pointers() {
}

template <typename T>
bool GenericVector<T>::write(FILE *f, std::function<bool(FILE *, const T &)> cb) const {
bool GenericVector<T>::write(FILE *f, const std::function<bool(FILE *, const T &)> &cb) const {
if (fwrite(&size_reserved_, sizeof(size_reserved_), 1, f) != 1) {
return false;
}
Expand All @@ -649,7 +649,7 @@ bool GenericVector<T>::write(FILE *f, std::function<bool(FILE *, const T &)> cb)
}

template <typename T>
bool GenericVector<T>::read(TFile *f, std::function<bool(TFile *, T *)> cb) {
bool GenericVector<T>::read(TFile *f, const std::function<bool(TFile *, T *)> &cb) {
int32_t reserved;
if (f->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/ccutil/unicity_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class UnicityTable {

/// Add a callback to be called to delete the elements when the table took
/// their ownership.
void set_clear_callback(std::function<void(T)> cb) {
void set_clear_callback(const std::function<void(T)> &cb) {
table_.set_clear_callback(cb);
}

Expand All @@ -109,10 +109,10 @@ class UnicityTable {
/// The Callback given must be permanent since they will be called more than
/// once. The given callback will be deleted at the end.
/// Returns false on read/write error.
bool write(FILE *f, std::function<bool(FILE *, const T &)> cb) const {
bool write(FILE *f, const std::function<bool(FILE *, const T &)> &cb) const {
return table_.write(f, cb);
}
bool read(tesseract::TFile *f, std::function<bool(tesseract::TFile *, T *)> cb) {
bool read(tesseract::TFile *f, const std::function<bool(tesseract::TFile *, T *)> &cb) {
return table_.read(f, cb);
}

Expand Down

0 comments on commit b86afd6

Please sign in to comment.