From 91920c4b0de1d69a03a89649c7e72fec1b539deb Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 11 Dec 2022 22:36:39 +0100 Subject: [PATCH] Fix function Classify::WriteIntTemplates (issue #3965) It crashed when running mftraining because unicharset_size in file "inttemp" was written with 8 bytes instead of 4 bytes. Signed-off-by: Stefan Weil --- src/classify/intproto.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp index e88e7959d0..8ca8bfc910 100644 --- a/src/classify/intproto.cpp +++ b/src/classify/intproto.cpp @@ -919,13 +919,13 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window) { void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES_STRUCT *Templates, const UNICHARSET &target_unicharset) { INT_CLASS_STRUCT *Class; - auto unicharset_size = target_unicharset.size(); + uint32_t unicharset_size = target_unicharset.size(); int version_id = -5; // When negated by the reader -1 becomes +1 etc. if (Templates->NumClasses != unicharset_size) { tprintf( "Warning: executing WriteIntTemplates() with %d classes in" - " Templates, while target_unicharset size is %zu\n", + " Templates, while target_unicharset size is %" PRIu32 "\n", Templates->NumClasses, unicharset_size); } @@ -947,6 +947,8 @@ void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES_STRUCT *Templates, /* first write out the high level struct for the class */ fwrite(&Class->NumProtos, sizeof(Class->NumProtos), 1, File); fwrite(&Class->NumProtoSets, sizeof(Class->NumProtoSets), 1, File); + printf("size of fontset_table_: %d, size of fontset %d: %zu (%u)\n", + fontset_table_.size(), Class->font_set_id, fontset_table_.at(Class->font_set_id).size(), Class->NumConfigs); ASSERT_HOST(Class->NumConfigs == this->fontset_table_.at(Class->font_set_id).size()); fwrite(&Class->NumConfigs, sizeof(Class->NumConfigs), 1, File); for (int j = 0; j < Class->NumConfigs; ++j) {