Skip to content

Commit 631882a

Browse files
committed
Fix compiler warnings (signed / unsigned mismatch)
clang warnings: src/ccutil/unicharcompress.cpp:172:27: warning: comparison of integers of different signs: 'int' and 'std::__cxx1998::vector::size_type' (aka 'unsigned long') [-Wsign-compare] src/lstm/recodebeam.cpp:129:29: warning: comparison of integers of different signs: 'std::__cxx1998::vector::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare] src/lstm/recodebeam.cpp:276:48: warning: comparison of integers of different signs: 'std::__cxx1998::vector::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare] unittest/imagedata_test.cc:101:21: warning: comparison of integers of different signs: 'int' and 'std::__cxx1998::vector::size_type' (aka 'unsigned long') [-Wsign-compare] unittest/linlsq_test.cc:33:23: warning: comparison of integers of different signs: 'int' and 'std::__cxx1998::vector::size_type' (aka 'unsigned long') [-Wsign-compare] unittest/linlsq_test.cc:44:23: warning: comparison of integers of different signs: 'int' and 'std::__cxx1998::vector::size_type' (aka 'unsigned long') [-Wsign-compare] unittest/nthitem_test.cc:27:23: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] unittest/nthitem_test.cc:68:21: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] unittest/stats_test.cc:26:23: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] Signed-off-by: Stefan Weil <[email protected]>
1 parent ecaad2a commit 631882a

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

src/ccutil/unicharcompress.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// place of a single large code for CJK, similarly for Indic,
55
// and dissection of ligatures for other scripts.
66
// Author: Ray Smith
7-
// Created: Wed Mar 04 14:45:01 PST 2015
87
//
98
// (C) Copyright 2015, Google Inc.
109
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -169,7 +168,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET& unicharset, int null_id,
169168
} else {
170169
// Add the direct_set unichar-ids of the unicodes in sequence to the
171170
// code.
172-
for (int i = 0; i < unicodes.size(); ++i) {
171+
for (size_t i = 0; i < unicodes.size(); ++i) {
173172
int position = code.length();
174173
if (position >= RecodedCharID::kMaxCodeLen) {
175174
tprintf("Unichar %d=%s is too long to encode!!\n", u,

src/lstm/recodebeam.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void RecodeBeamSearch::SaveMostCertainChoices(const float* outputs,
112112
const UNICHARSET* charset,
113113
int xCoord) {
114114
std::vector<std::pair<const char*, float>> choices;
115-
int pos = 0;
116115
for (int i = 0; i < num_outputs; ++i) {
117116
if (outputs[i] >= 0.01f) {
118117
const char* character;
@@ -123,7 +122,7 @@ void RecodeBeamSearch::SaveMostCertainChoices(const float* outputs,
123122
} else {
124123
character = charset->id_to_unichar_ext(i);
125124
}
126-
pos = 0;
125+
size_t pos = 0;
127126
//order the possible choices within one timestep
128127
//beginning with the most likely
129128
while (choices.size() > pos && choices[pos].second > outputs[i]) {
@@ -267,12 +266,11 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
267266
summed_propabilities[it->first] += it->second;
268267
}
269268
std::vector<std::pair<const char*, float>> accumulated_timestep;
270-
int pos;
271269
for (auto it = summed_propabilities.begin();
272270
it != summed_propabilities.end(); ++it) {
273271
if(sum == 0) break;
274272
it->second/=sum;
275-
pos = 0;
273+
size_t pos = 0;
276274
while (accumulated_timestep.size() > pos
277275
&& accumulated_timestep[pos].second > it->second) {
278276
pos++;

unittest/imagedata_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ImagedataTest : public ::testing::Test {
3232
ImagedataTest() {}
3333

3434
// Creates a fake DocumentData, writes it to a file, and returns the filename.
35-
std::string MakeFakeDoc(int num_pages, int doc_id,
35+
std::string MakeFakeDoc(int num_pages, unsigned doc_id,
3636
std::vector<std::string>* page_texts) {
3737
// The size of the fake images that we will use.
3838
const int kImageSize = 1048576;
@@ -43,7 +43,7 @@ class ImagedataTest : public ::testing::Test {
4343
for (int p = 0; p < num_pages; ++p) {
4444
// Make some fake text that is different for each page and save it.
4545
page_texts->push_back(
46-
absl::StrFormat("Page %d of %d in doc %d", p, num_pages, doc_id));
46+
absl::StrFormat("Page %d of %d in doc %u", p, num_pages, doc_id));
4747
// Make an imagedata and put it in the document.
4848
ImageData* imagedata =
4949
ImageData::Build("noname", p, "eng", fake_image.data(),
@@ -98,7 +98,7 @@ TEST_F(ImagedataTest, CachesMultiDocs) {
9898
const std::vector<int> kNumPages = {6, 5, 7};
9999
std::vector<std::vector<std::string>> page_texts;
100100
GenericVector<STRING> filenames;
101-
for (int d = 0; d < kNumPages.size(); ++d) {
101+
for (size_t d = 0; d < kNumPages.size(); ++d) {
102102
page_texts.emplace_back(std::vector<std::string>());
103103
std::string filename = MakeFakeDoc(kNumPages[d], d, &page_texts.back());
104104
filenames.push_back(STRING(filename.c_str()));

unittest/linlsq_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LLSQTest : public testing::Test {
3030
}
3131
FCOORD PtsMean(const std::vector<FCOORD>& pts) {
3232
FCOORD total(0, 0);
33-
for (int i = 0; i < pts.size(); i++) {
33+
for (size_t i = 0; i < pts.size(); i++) {
3434
total += pts[i];
3535
}
3636
return (pts.size() > 0) ? total / pts.size() : total;
@@ -41,7 +41,7 @@ class LLSQTest : public testing::Test {
4141
FCOORD nvec = !orth;
4242
nvec.normalise();
4343
double expected_answer = 0;
44-
for (int i = 0; i < pts.size(); i++) {
44+
for (size_t i = 0; i < pts.size(); i++) {
4545
llsq.add(pts[i].x(), pts[i].y());
4646
double dot = nvec % (pts[i] - xavg);
4747
expected_answer += dot * dot;

unittest/nthitem_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class NthItemTest : public testing::Test {
2424
virtual ~NthItemTest();
2525
// Pushes the test data onto the KDVector.
2626
void PushTestData(KDVector* v) {
27-
for (int i = 0; i < ARRAYSIZE(test_data); ++i) {
27+
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
2828
IntKDPair pair(test_data[i], i);
2929
v->push_back(pair);
3030
}
@@ -65,7 +65,7 @@ TEST_F(NthItemTest, BoringTest) {
6565
KDVector v;
6666
// Push the test data onto the KDVector.
6767
int test_data[] = {8, 8, 8, 8, 8, 7, 7, 7, 7};
68-
for (int i = 0; i < ARRAYSIZE(test_data); ++i) {
68+
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
6969
IntKDPair pair(test_data[i], i);
7070
v.push_back(pair);
7171
}

unittest/stats_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class STATSTest : public testing::Test {
2323
public:
2424
void SetUp() {
2525
stats_.set_range(0, 16);
26-
for (int i = 0; i < ARRAYSIZE(kTestData); ++i)
26+
for (size_t i = 0; i < ARRAYSIZE(kTestData); ++i)
2727
stats_.add(i, kTestData[i]);
2828
}
2929

0 commit comments

Comments
 (0)