Skip to content

Commit

Permalink
Fix compiler warnings (signed / unsigned mismatch)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stweil committed Mar 25, 2019
1 parent ecaad2a commit 631882a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/ccutil/unicharcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// place of a single large code for CJK, similarly for Indic,
// and dissection of ligatures for other scripts.
// Author: Ray Smith
// Created: Wed Mar 04 14:45:01 PST 2015
//
// (C) Copyright 2015, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -169,7 +168,7 @@ bool UnicharCompress::ComputeEncoding(const UNICHARSET& unicharset, int null_id,
} else {
// Add the direct_set unichar-ids of the unicodes in sequence to the
// code.
for (int i = 0; i < unicodes.size(); ++i) {
for (size_t i = 0; i < unicodes.size(); ++i) {
int position = code.length();
if (position >= RecodedCharID::kMaxCodeLen) {
tprintf("Unichar %d=%s is too long to encode!!\n", u,
Expand Down
6 changes: 2 additions & 4 deletions src/lstm/recodebeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void RecodeBeamSearch::SaveMostCertainChoices(const float* outputs,
const UNICHARSET* charset,
int xCoord) {
std::vector<std::pair<const char*, float>> choices;
int pos = 0;
for (int i = 0; i < num_outputs; ++i) {
if (outputs[i] >= 0.01f) {
const char* character;
Expand All @@ -123,7 +122,7 @@ void RecodeBeamSearch::SaveMostCertainChoices(const float* outputs,
} else {
character = charset->id_to_unichar_ext(i);
}
pos = 0;
size_t pos = 0;
//order the possible choices within one timestep
//beginning with the most likely
while (choices.size() > pos && choices[pos].second > outputs[i]) {
Expand Down Expand Up @@ -267,12 +266,11 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
summed_propabilities[it->first] += it->second;
}
std::vector<std::pair<const char*, float>> accumulated_timestep;
int pos;
for (auto it = summed_propabilities.begin();
it != summed_propabilities.end(); ++it) {
if(sum == 0) break;
it->second/=sum;
pos = 0;
size_t pos = 0;
while (accumulated_timestep.size() > pos
&& accumulated_timestep[pos].second > it->second) {
pos++;
Expand Down
6 changes: 3 additions & 3 deletions unittest/imagedata_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ImagedataTest : public ::testing::Test {
ImagedataTest() {}

// Creates a fake DocumentData, writes it to a file, and returns the filename.
std::string MakeFakeDoc(int num_pages, int doc_id,
std::string MakeFakeDoc(int num_pages, unsigned doc_id,
std::vector<std::string>* page_texts) {
// The size of the fake images that we will use.
const int kImageSize = 1048576;
Expand All @@ -43,7 +43,7 @@ class ImagedataTest : public ::testing::Test {
for (int p = 0; p < num_pages; ++p) {
// Make some fake text that is different for each page and save it.
page_texts->push_back(
absl::StrFormat("Page %d of %d in doc %d", p, num_pages, doc_id));
absl::StrFormat("Page %d of %d in doc %u", p, num_pages, doc_id));
// Make an imagedata and put it in the document.
ImageData* imagedata =
ImageData::Build("noname", p, "eng", fake_image.data(),
Expand Down Expand Up @@ -98,7 +98,7 @@ TEST_F(ImagedataTest, CachesMultiDocs) {
const std::vector<int> kNumPages = {6, 5, 7};
std::vector<std::vector<std::string>> page_texts;
GenericVector<STRING> filenames;
for (int d = 0; d < kNumPages.size(); ++d) {
for (size_t d = 0; d < kNumPages.size(); ++d) {
page_texts.emplace_back(std::vector<std::string>());
std::string filename = MakeFakeDoc(kNumPages[d], d, &page_texts.back());
filenames.push_back(STRING(filename.c_str()));
Expand Down
4 changes: 2 additions & 2 deletions unittest/linlsq_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LLSQTest : public testing::Test {
}
FCOORD PtsMean(const std::vector<FCOORD>& pts) {
FCOORD total(0, 0);
for (int i = 0; i < pts.size(); i++) {
for (size_t i = 0; i < pts.size(); i++) {

This comment has been minimized.

Copy link
@egorpugin

egorpugin Mar 25, 2019

Contributor

Can be replaced with range-for loops.

for (const auto &p : pts)
    total += p;

And other places too.

See #2320

This comment has been minimized.

Copy link
@stweil

stweil Mar 25, 2019

Author Member

Done. Thank you. I still have to get used to the new possibilities.

total += pts[i];
}
return (pts.size() > 0) ? total / pts.size() : total;
Expand All @@ -41,7 +41,7 @@ class LLSQTest : public testing::Test {
FCOORD nvec = !orth;
nvec.normalise();
double expected_answer = 0;
for (int i = 0; i < pts.size(); i++) {
for (size_t i = 0; i < pts.size(); i++) {
llsq.add(pts[i].x(), pts[i].y());
double dot = nvec % (pts[i] - xavg);
expected_answer += dot * dot;
Expand Down
4 changes: 2 additions & 2 deletions unittest/nthitem_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NthItemTest : public testing::Test {
virtual ~NthItemTest();
// Pushes the test data onto the KDVector.
void PushTestData(KDVector* v) {
for (int i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
IntKDPair pair(test_data[i], i);
v->push_back(pair);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ TEST_F(NthItemTest, BoringTest) {
KDVector v;
// Push the test data onto the KDVector.
int test_data[] = {8, 8, 8, 8, 8, 7, 7, 7, 7};
for (int i = 0; i < ARRAYSIZE(test_data); ++i) {
for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
IntKDPair pair(test_data[i], i);
v.push_back(pair);
}
Expand Down
2 changes: 1 addition & 1 deletion unittest/stats_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class STATSTest : public testing::Test {
public:
void SetUp() {
stats_.set_range(0, 16);
for (int i = 0; i < ARRAYSIZE(kTestData); ++i)
for (size_t i = 0; i < ARRAYSIZE(kTestData); ++i)
stats_.add(i, kTestData[i]);
}

Expand Down

0 comments on commit 631882a

Please sign in to comment.