Skip to content

Commit

Permalink
Add missing serialization to FILE for vector of pointers (issue #3925)
Browse files Browse the repository at this point in the history
It is required for mftraining which otherwise writes a wrong shapetable.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Dec 13, 2022
1 parent 90c09a3 commit 6b7cb1c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ccutil/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <string>
#include <vector>

#include "serialis.h"

namespace tesseract {

template <class T>
Expand Down Expand Up @@ -242,6 +244,19 @@ bool Serialize(FILE *fp, const std::vector<T> &data) {
return false;
}
}
} else if constexpr (std::is_pointer<T>::value) {
// Serialize pointers.
for (auto &item : data) {
uint8_t non_null = (item != nullptr);
if (!Serialize(fp, &non_null)) {
return false;
}
if (non_null) {
if (!item->Serialize(fp)) {
return false;
}
}
}
} else if (size > 0) {
if (fwrite(&data[0], sizeof(T), size, fp) != size) {
return false;
Expand Down

0 comments on commit 6b7cb1c

Please sign in to comment.