Skip to content

Commit

Permalink
Fix more signed/unsigned compiler warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 10, 2021
1 parent 86d981e commit 842cca1
Show file tree
Hide file tree
Showing 30 changed files with 224 additions and 226 deletions.
4 changes: 1 addition & 3 deletions src/ccstruct/mod128.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**********************************************************************
* File: mod128.h (Formerly dir128.h)
* Description: Header for class which implements modulo arithmetic.
* Author: Ray Smith
* Created: Tue Mar 26 17:48:13 GMT 1991
* Author: Ray Smith
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -81,7 +80,6 @@ class DIR128 {
return dir;
}

private:
int8_t dir; // a direction
};

Expand Down
12 changes: 6 additions & 6 deletions src/ccstruct/pageres.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class TESS_API WERD_RES : public ELIST_LINK {
return nullptr;
}
UNICHAR_ID id = best_choice->unichar_id(blob_index);
if (id < 0 || id >= uch_set->size()) {
if (static_cast<unsigned>(id) >= uch_set->size()) {
return nullptr;
}
UNICHAR_ID mirrored = uch_set->get_mirror(id);
Expand All @@ -377,7 +377,7 @@ class TESS_API WERD_RES : public ELIST_LINK {
return nullptr;
}
UNICHAR_ID id = raw_choice->unichar_id(blob_index);
if (id < 0 || id >= uch_set->size()) {
if (static_cast<unsigned>(id) >= uch_set->size()) {
return nullptr;
}
return uch_set->id_to_unichar(id);
Expand All @@ -395,8 +395,8 @@ class TESS_API WERD_RES : public ELIST_LINK {
return false;
}
for (unsigned id = 0; id < best_choice->length(); id++) {
int unichar_id = best_choice->unichar_id(id);
if (unichar_id < 0 || unichar_id >= uch_set->size()) {
unsigned unichar_id = best_choice->unichar_id(id);
if (unichar_id >= uch_set->size()) {
continue; // Ignore illegal chars.
}
UNICHARSET::Direction dir = uch_set->get_direction(unichar_id);
Expand All @@ -412,8 +412,8 @@ class TESS_API WERD_RES : public ELIST_LINK {
return false;
}
for (unsigned id = 0; id < best_choice->length(); id++) {
int unichar_id = best_choice->unichar_id(id);
if (unichar_id < 0 || unichar_id >= uch_set->size()) {
unsigned unichar_id = best_choice->unichar_id(id);
if (unichar_id >= uch_set->size()) {
continue; // Ignore illegal chars.
}
UNICHARSET::Direction dir = uch_set->get_direction(unichar_id);
Expand Down
18 changes: 9 additions & 9 deletions src/ccutil/ambigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ AmbigSpec::AmbigSpec() {

// Initializes the ambigs by adding a nullptr pointer to each table.
void UnicharAmbigs::InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption) {
for (int i = 0; i < unicharset.size(); ++i) {
for (unsigned i = 0; i < unicharset.size(); ++i) {
replace_ambigs_.push_back(nullptr);
dang_ambigs_.push_back(nullptr);
one_to_one_definite_ambigs_.push_back(nullptr);
Expand All @@ -72,7 +72,6 @@ void UnicharAmbigs::LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *uni
void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambig_file,
int debug_level, bool use_ambigs_for_adaption,
UNICHARSET *unicharset) {
int i, j;
UnicharIdVector *adaption_ambigs_entry;
if (debug_level) {
tprintf("Reading ambiguities\n");
Expand Down Expand Up @@ -130,7 +129,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi
// Silently ignore invalid strings, as before, so it is safe to use a
// universal ambigs file.
if (unicharset->encode_string(replacement_string, true, &encoding, nullptr, nullptr)) {
for (i = 0; i < test_ambig_part_size; ++i) {
for (int i = 0; i < test_ambig_part_size; ++i) {
if (ambigs_for_adaption_[test_unichar_ids[i]] == nullptr) {
ambigs_for_adaption_[test_unichar_ids[i]] = new UnicharIdVector();
}
Expand All @@ -139,6 +138,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi
ASSERT_HOST(id_to_insert != INVALID_UNICHAR_ID);
// Add the new unichar id to adaption_ambigs_entry (only if the
// vector does not already contain it) keeping it in sorted order.
size_t j;
for (j = 0;
j < adaption_ambigs_entry->size() && (*adaption_ambigs_entry)[j] > id_to_insert;
++j) {
Expand All @@ -160,12 +160,12 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi

// Fill in reverse_ambigs_for_adaption from ambigs_for_adaption vector.
if (use_ambigs_for_adaption) {
for (i = 0; i < ambigs_for_adaption_.size(); ++i) {
for (size_t i = 0; i < ambigs_for_adaption_.size(); ++i) {
adaption_ambigs_entry = ambigs_for_adaption_[i];
if (adaption_ambigs_entry == nullptr) {
continue;
}
for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
for (size_t j = 0; j < adaption_ambigs_entry->size(); ++j) {
UNICHAR_ID ambig_id = (*adaption_ambigs_entry)[j];
if (reverse_ambigs_for_adaption_[ambig_id] == nullptr) {
reverse_ambigs_for_adaption_[ambig_id] = new UnicharIdVector();
Expand All @@ -179,7 +179,7 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi
if (debug_level > 1) {
for (int tbl = 0; tbl < 2; ++tbl) {
const UnicharAmbigsVector &print_table = (tbl == 0) ? replace_ambigs_ : dang_ambigs_;
for (i = 0; i < print_table.size(); ++i) {
for (size_t i = 0; i < print_table.size(); ++i) {
AmbigSpec_LIST *lst = print_table[i];
if (lst == nullptr) {
continue;
Expand All @@ -202,12 +202,12 @@ void UnicharAmbigs::LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambi
for (int vec_id = 0; vec_id < 2; ++vec_id) {
const std::vector<UnicharIdVector *> &vec =
(vec_id == 0) ? ambigs_for_adaption_ : reverse_ambigs_for_adaption_;
for (i = 0; i < vec.size(); ++i) {
for (size_t i = 0; i < vec.size(); ++i) {
adaption_ambigs_entry = vec[i];
if (adaption_ambigs_entry != nullptr) {
tprintf("%sAmbigs for adaption for %s:\n", (vec_id == 0) ? "" : "Reverse ",
unicharset->debug_str(i).c_str());
for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
for (size_t j = 0; j < adaption_ambigs_entry->size(); ++j) {
tprintf("%s ", unicharset->debug_str((*adaption_ambigs_entry)[j]).c_str());
}
tprintf("\n");
Expand Down Expand Up @@ -246,7 +246,7 @@ bool UnicharAmbigs::ParseAmbiguityLine(int line_num, int version, int debug_leve
return false;
}
// Copy encoded string to output.
for (int i = 0; i < unichars.size(); ++i) {
for (size_t i = 0; i < unichars.size(); ++i) {
test_unichar_ids[i] = unichars[i];
}
test_unichar_ids[unichars.size()] = INVALID_UNICHAR_ID;
Expand Down
6 changes: 3 additions & 3 deletions src/ccutil/indexmapbidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ bool IndexMapBiDi::Serialize(FILE *fp) const {
// then each additional sparse entry needs to be stored.
// Normally we store only the compact map to save space.
std::vector<int32_t> remaining_pairs;
for (size_t i = 0; i < sparse_map_.size(); ++i) {
if (sparse_map_[i] >= 0 && compact_map_[sparse_map_[i]] != i) {
for (unsigned i = 0; i < sparse_map_.size(); ++i) {
if (sparse_map_[i] >= 0 && static_cast<unsigned>(compact_map_[sparse_map_[i]]) != i) {
remaining_pairs.push_back(i);
remaining_pairs.push_back(sparse_map_[i]);
}
Expand All @@ -243,7 +243,7 @@ bool IndexMapBiDi::DeSerialize(bool swap, FILE *fp) {
}
sparse_map_.clear();
sparse_map_.resize(sparse_size_, -1);
for (size_t i = 0; i < compact_map_.size(); ++i) {
for (unsigned i = 0; i < compact_map_.size(); ++i) {
sparse_map_[compact_map_[i]] = i;
}
for (size_t i = 0; i < remaining_pairs.size(); ++i) {
Expand Down
20 changes: 10 additions & 10 deletions src/ccutil/unicharcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static bool DecodeRadicalLine(std::string &radical_data_line, RSMap *radical_map
return false;
}
std::unique_ptr<std::vector<int>> radicals(new std::vector<int>);
for (int i = 1; i < entries.size(); ++i) {
for (size_t i = 1; i < entries.size(); ++i) {
int radical = strtol(&entries[i][0], &end, 10);
if (*end != '\0') {
return false;
Expand Down Expand Up @@ -132,10 +132,10 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET &unicharset, int null_id,
// to measure the number of radicals and strokes, initially we use the same
// code range for all 3 Han code positions, and fix them after.
int han_offset = hangul_offset + kTotalJamos;
for (int u = 0; u <= unicharset.size(); ++u) {
for (unsigned u = 0; u <= unicharset.size(); ++u) {
// We special-case allow null_id to be equal to unicharset.size() in case
// there is no space in unicharset for it.
if (u == unicharset.size() && u != null_id) {
if (u == unicharset.size() && static_cast<int>(u) != null_id) {
break; // Finished
}
RecodedCharID code;
Expand Down Expand Up @@ -173,7 +173,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET &unicharset, int null_id,
// Special cases.
if (u == UNICHAR_SPACE) {
code.Set(0, 0); // Space.
} else if (u == null_id ||
} else if (static_cast<int>(u) == null_id ||
(unicharset.has_special_codes() && u < SPECIAL_UNICHAR_CODES_COUNT)) {
code.Set(0, direct_set.unichar_to_id(kNullChar));
} else {
Expand Down Expand Up @@ -207,7 +207,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET &unicharset, int null_id,
int code_offset = 0;
for (int i = 0; i < RecodedCharID::kMaxCodeLen; ++i) {
int max_offset = 0;
for (int u = 0; u < unicharset.size(); ++u) {
for (unsigned u = 0; u < unicharset.size(); ++u) {
RecodedCharID *code = &encoder_[u];
if (code->length() <= i) {
continue;
Expand All @@ -229,7 +229,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET &unicharset, int null_id,
// passes them through unchanged.
void UnicharCompress::SetupPassThrough(const UNICHARSET &unicharset) {
std::vector<RecodedCharID> codes;
for (int u = 0; u < unicharset.size(); ++u) {
for (unsigned u = 0; u < unicharset.size(); ++u) {
RecodedCharID code;
code.Set(0, u);
codes.push_back(code);
Expand Down Expand Up @@ -268,7 +268,7 @@ void UnicharCompress::DefragmentCodeValues(int encoded_null) {
for (unsigned i = 0; i < offsets.size(); ++i) {
// If not used, decrement everything above here.
// We are moving encoded_null to the end, so it is not "used".
if (offsets[i] == 0 || i == encoded_null) {
if (offsets[i] == 0 || i == static_cast<unsigned>(encoded_null)) {
--offset;
} else {
offsets[i] = offset;
Expand All @@ -292,8 +292,8 @@ void UnicharCompress::DefragmentCodeValues(int encoded_null) {

// Encodes a single unichar_id. Returns the length of the code, or zero if
// invalid input, and the encoding itself
int UnicharCompress::EncodeUnichar(int unichar_id, RecodedCharID *code) const {
if (unichar_id < 0 || unichar_id >= encoder_.size()) {
int UnicharCompress::EncodeUnichar(unsigned unichar_id, RecodedCharID *code) const {
if (unichar_id >= encoder_.size()) {
return 0;
}
*code = encoder_[unichar_id];
Expand Down Expand Up @@ -397,7 +397,7 @@ void UnicharCompress::SetupDecoder() {
Cleanup();
is_valid_start_.clear();
is_valid_start_.resize(code_range_);
for (int c = 0; c < encoder_.size(); ++c) {
for (unsigned c = 0; c < encoder_.size(); ++c) {
const RecodedCharID &code = encoder_[c];
decoder_[code] = c;
is_valid_start_[code(0)] = true;
Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/unicharcompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class TESS_API UnicharCompress {

// Encodes a single unichar_id. Returns the length of the code, (or zero if
// invalid input), and the encoding itself in code.
int EncodeUnichar(int unichar_id, RecodedCharID *code) const;
int EncodeUnichar(unsigned unichar_id, RecodedCharID *code) const;
// Decodes code, returning the original unichar-id, or
// INVALID_UNICHAR_ID if the input is invalid.
int DecodeUnichar(const RecodedCharID &code) const;
Expand Down
14 changes: 7 additions & 7 deletions src/ccutil/unicharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ const char *UNICHARSET::id_to_unichar(UNICHAR_ID id) const {
if (id == INVALID_UNICHAR_ID) {
return INVALID_UNICHAR;
}
ASSERT_HOST(id < this->size());
ASSERT_HOST(static_cast<unsigned>(id) < this->size());
return unichars[id].representation;
}

const char *UNICHARSET::id_to_unichar_ext(UNICHAR_ID id) const {
if (id == INVALID_UNICHAR_ID) {
return INVALID_UNICHAR;
}
ASSERT_HOST(id < this->size());
ASSERT_HOST(static_cast<unsigned>(id) < this->size());
// Resolve from the kCustomLigatures table if this is a private encoding.
if (get_isprivate(id)) {
const char *ch = id_to_unichar(id);
Expand Down Expand Up @@ -384,7 +384,7 @@ void UNICHARSET::set_ranges_empty() {
// everything set. The unicharsets don't have to be the same, and graphemes
// are correctly accounted for.
void UNICHARSET::PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src) {
for (int ch = start_index; ch < unichars.size(); ++ch) {
for (unsigned ch = start_index; ch < unichars.size(); ++ch) {
const char *utf8 = id_to_unichar(ch);
UNICHAR_PROPERTIES properties;
if (src.GetStrProperties(utf8, &properties)) {
Expand Down Expand Up @@ -481,7 +481,7 @@ void UNICHARSET::encode_string(const char *str, int str_index, int str_length,
std::vector<UNICHAR_ID> *encoding, std::vector<char> *lengths,
unsigned *best_total_length, std::vector<UNICHAR_ID> *best_encoding,
std::vector<char> *best_lengths) const {
if (str_index > *best_total_length) {
if (str_index > static_cast<int>(*best_total_length)) {
// This is the best result so far.
*best_total_length = str_index;
*best_encoding = *encoding;
Expand All @@ -506,7 +506,7 @@ void UNICHARSET::encode_string(const char *str, int str_index, int str_length,
lengths->push_back(length);
encode_string(str, str_index + length, str_length, encoding, lengths, best_total_length,
best_encoding, best_lengths);
if (*best_total_length == str_length) {
if (static_cast<int>(*best_total_length) == str_length) {
return; // Tail recursion success!
}
// Failed with that length, truncate back and try again.
Expand Down Expand Up @@ -695,9 +695,9 @@ bool UNICHARSET::eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
bool UNICHARSET::save_to_string(std::string &str) const {
const int kFileBufSize = 1024;
char buffer[kFileBufSize + 1];
snprintf(buffer, kFileBufSize, "%d\n", this->size());
snprintf(buffer, kFileBufSize, "%zu\n", this->size());
str = buffer;
for (UNICHAR_ID id = 0; id < this->size(); ++id) {
for (unsigned id = 0; id < this->size(); ++id) {
int min_bottom, max_bottom, min_top, max_top;
get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);
float width, width_sd;
Expand Down
4 changes: 2 additions & 2 deletions src/ccutil/unicharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class TESS_API UNICHARSET {
if (cleaned != unichar_repr) {
unichar_insert(unichar_repr, OldUncleanUnichars::kTrue);
} else {
int old_size = size();
auto old_size = size();
unichar_insert(unichar_repr, OldUncleanUnichars::kFalse);
if (size() == old_size) {
unichar_insert(unichar_repr, OldUncleanUnichars::kTrue);
Expand Down Expand Up @@ -345,7 +345,7 @@ class TESS_API UNICHARSET {
}

// Return the size of the set (the number of different UNICHAR it holds).
int size() const {
size_t size() const {
return unichars.size();
}

Expand Down
14 changes: 6 additions & 8 deletions src/classify/adaptive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ADAPT_TEMPLATES_STRUCT::ADAPT_TEMPLATES_STRUCT(UNICHARSET &unicharset) {
NumNonEmptyClasses = 0;

/* Insert an empty class for each unichar id in unicharset */
for (int i = 0; i < MAX_NUM_CLASSES; i++) {
for (unsigned i = 0; i < MAX_NUM_CLASSES; i++) {
Class[i] = nullptr;
if (i < unicharset.size()) {
AddAdaptedClass(this, new ADAPT_CLASS_STRUCT, i);
Expand All @@ -108,7 +108,7 @@ ADAPT_TEMPLATES_STRUCT::ADAPT_TEMPLATES_STRUCT(UNICHARSET &unicharset) {
}

ADAPT_TEMPLATES_STRUCT::~ADAPT_TEMPLATES_STRUCT() {
for (int i = 0; i < (Templates)->NumClasses; i++) {
for (unsigned i = 0; i < (Templates)->NumClasses; i++) {
delete Class[i];
}
delete Templates;
Expand Down Expand Up @@ -160,11 +160,11 @@ void Classify::PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES_STRUCT *Templat
fprintf(File, " Id NC NPC NP NPP\n");
fprintf(File, "------------------------\n");

for (int i = 0; i < (Templates->Templates)->NumClasses; i++) {
for (unsigned i = 0; i < (Templates->Templates)->NumClasses; i++) {
IClass = Templates->Templates->Class[i];
AClass = Templates->Class[i];
if (!IsEmptyAdaptedClass(AClass)) {
fprintf(File, "%5d %s %3d %3d %3d %3zd\n", i, unicharset.id_to_unichar(i), IClass->NumConfigs,
fprintf(File, "%5u %s %3d %3d %3d %3zd\n", i, unicharset.id_to_unichar(i), IClass->NumConfigs,
AClass->NumPermConfigs, IClass->NumProtos,
IClass->NumProtos - AClass->TempProtos->size());
}
Expand Down Expand Up @@ -242,7 +242,7 @@ ADAPT_TEMPLATES_STRUCT *Classify::ReadAdaptedTemplates(TFile *fp) {
Templates->Templates = ReadIntTemplates(fp);

/* then read in the adaptive info for each class */
for (int i = 0; i < (Templates->Templates)->NumClasses; i++) {
for (unsigned i = 0; i < (Templates->Templates)->NumClasses; i++) {
Templates->Class[i] = ReadAdaptedClass(fp);
}
return (Templates);
Expand Down Expand Up @@ -343,16 +343,14 @@ void WriteAdaptedClass(FILE *File, ADAPT_CLASS_STRUCT *Class, int NumConfigs) {
* @note Globals: none
*/
void Classify::WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES_STRUCT *Templates) {
int i;

/* first write the high level adaptive template struct */
fwrite(Templates, sizeof(ADAPT_TEMPLATES_STRUCT), 1, File);

/* then write out the basic integer templates */
WriteIntTemplates(File, Templates->Templates, unicharset);

/* then write out the adaptive info for each class */
for (i = 0; i < (Templates->Templates)->NumClasses; i++) {
for (unsigned i = 0; i < (Templates->Templates)->NumClasses; i++) {
WriteAdaptedClass(File, Templates->Class[i], Templates->Templates->Class[i]->NumConfigs);
}
} /* WriteAdaptedTemplates */
Expand Down
Loading

0 comments on commit 842cca1

Please sign in to comment.