Skip to content

Too many warnings! #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/pdfrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ bool TessPDFRenderer::BeginDocumentHandler() {
long int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
const std::unique_ptr</*non-const*/ char[]> buffer(new char[size]);
if (fread(buffer.get(), 1, size, fp) != size) {
if (fread(buffer.get(), 1, size, fp) != static_cast<unsigned long>(size)) {
fclose(fp);
return false;
}
Expand Down Expand Up @@ -945,7 +945,7 @@ bool TessPDFRenderer::EndDocumentHandler() {
if (n >= sizeof(buf)) return false;
AppendString(buf);
size_t pages_objsize = strlen(buf);
for (size_t i = 0; i < pages_.size(); i++) {
for (size_t i = 0; i < pages_.unsigned_size(); i++) {
n = snprintf(buf, sizeof(buf),
"%ld 0 R ", pages_[i]);
if (n >= sizeof(buf)) return false;
Expand Down
2 changes: 1 addition & 1 deletion ccmain/docqual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ BOOL8 Tesseract::terrible_word_crunch(WERD_RES *word,

if ((word->best_choice->unichar_string().length () == 0) ||
(strspn (word->best_choice->unichar_string().string(), " ") ==
word->best_choice->unichar_string().length ()))
word->best_choice->unichar_string().unsigned_size ()))
crunch_mode = 1;
else {
adjusted_len = word->reject_map.length ();
Expand Down
18 changes: 12 additions & 6 deletions ccutil/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class GenericVector {
int size() const {
return size_used_;
}
// Workaround to avoid g++ -Wsign-compare warnings.
unsigned int unsigned_size() const {
static_assert(sizeof(size_used_) <= sizeof(unsigned int), "");
assert(0 <= size_used_);
return static_cast<unsigned int>(size_used_);
}
int size_reserved() const {
return size_reserved_;
}
Expand Down Expand Up @@ -880,7 +886,7 @@ bool GenericVector<T>::write(
}
delete cb;
} else {
if (fwrite(data_, sizeof(T), size_used_, f) != size_used_) return false;
if (fwrite(data_, sizeof(T), size_used_, f) != unsigned_size()) return false;
}
return true;
}
Expand Down Expand Up @@ -912,7 +918,7 @@ bool GenericVector<T>::read(
template <typename T>
bool GenericVector<T>::Serialize(FILE* fp) const {
if (fwrite(&size_used_, sizeof(size_used_), 1, fp) != 1) return false;
if (fwrite(data_, sizeof(*data_), size_used_, fp) != size_used_) return false;
if (fwrite(data_, sizeof(*data_), size_used_, fp) != unsigned_size()) return false;
return true;
}
template <typename T>
Expand All @@ -933,7 +939,7 @@ bool GenericVector<T>::DeSerialize(bool swap, FILE* fp) {
if (swap) Reverse32(&reserved);
reserve(reserved);
size_used_ = reserved;
if (fread(data_, sizeof(T), size_used_, fp) != size_used_) return false;
if (fread(data_, sizeof(T), size_used_, fp) != unsigned_size()) return false;
if (swap) {
for (int i = 0; i < size_used_; ++i)
ReverseN(&data_[i], sizeof(data_[i]));
Expand Down Expand Up @@ -982,7 +988,7 @@ bool GenericVector<T>::SerializeClasses(tesseract::TFile* fp) const {
// If swap is true, assumes a big/little-endian swap is needed.
template <typename T>
bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
uinT32 reserved;
inT32 reserved;
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
if (swap) Reverse32(&reserved);
T empty;
Expand All @@ -994,7 +1000,7 @@ bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
}
template <typename T>
bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
uinT32 reserved;
inT32 reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
T empty;
init_to_size(reserved, empty);
Expand All @@ -1005,7 +1011,7 @@ bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
}
template <typename T>
bool GenericVector<T>::SkipDeSerializeClasses(tesseract::TFile* fp) {
uinT32 reserved;
inT32 reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
for (int i = 0; i < reserved; ++i) {
if (!T::SkipDeSerialize(fp)) return false;
Expand Down
7 changes: 7 additions & 0 deletions ccutil/strngs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef STRNGS_H
#define STRNGS_H

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "platform.h"
Expand Down Expand Up @@ -66,6 +67,12 @@ class TESS_API STRING
BOOL8 contains(const char c) const;
inT32 length() const;
inT32 size() const { return length(); }
// Workaround to avoid g++ -Wsign-compare warnings.
uinT32 unsigned_size() const {
const inT32 len = length();
assert(0 <= len);
return static_cast<uinT32>(len);
}
const char *string() const;
const char *c_str() const;

Expand Down
2 changes: 1 addition & 1 deletion classify/blobclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void Classify::LearnBlob(const STRING& fontname, TBLOB* blob,
bool Classify::WriteTRFile(const STRING& filename) {
STRING tr_filename = filename + ".tr";
FILE* fp = Efopen(tr_filename.string(), "wb");
int len = tr_file_data_.length();
size_t len = tr_file_data_.length();
bool result =
fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len;
fclose(fp);
Expand Down
15 changes: 5 additions & 10 deletions classify/featdefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs) {
* @note History: Wed May 23 13:52:19 1990, DSJ, Created.
*/
void FreeCharDescription(CHAR_DESC CharDesc) {
int i;

if (CharDesc) {
for (i = 0; i < CharDesc->NumFeatureSets; i++)
for (size_t i = 0; i < CharDesc->NumFeatureSets; i++)
FreeFeatureSet (CharDesc->FeatureSets[i]);
Efree(CharDesc);
}
Expand All @@ -163,12 +161,10 @@ void FreeCharDescription(CHAR_DESC CharDesc) {
*/
CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
CHAR_DESC CharDesc;
int i;

CharDesc = (CHAR_DESC) Emalloc (sizeof (CHAR_DESC_STRUCT));
CharDesc->NumFeatureSets = FeatureDefs.NumFeatureTypes;

for (i = 0; i < CharDesc->NumFeatureSets; i++)
for (size_t i = 0; i < CharDesc->NumFeatureSets; i++)
CharDesc->FeatureSets[i] = NULL;

return (CharDesc);
Expand Down Expand Up @@ -196,16 +192,15 @@ CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
*/
void WriteCharDescription(const FEATURE_DEFS_STRUCT& FeatureDefs,
CHAR_DESC CharDesc, STRING* str) {
int Type;
int NumSetsToWrite = 0;

for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++)
if (CharDesc->FeatureSets[Type])
NumSetsToWrite++;

str->add_str_int(" ", NumSetsToWrite);
*str += "\n";
for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
if (CharDesc->FeatureSets[Type]) {
*str += FeatureDefs.FeatureDesc[Type]->ShortName;
*str += " ";
Expand All @@ -220,7 +215,7 @@ bool ValidCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
CHAR_DESC CharDesc) {
bool anything_written = false;
bool well_formed = true;
for (int Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
for (size_t Type = 0; Type < CharDesc->NumFeatureSets; Type++) {
if (CharDesc->FeatureSets[Type]) {
for (int i = 0; i < CharDesc->FeatureSets[Type]->NumFeatures; i++) {
FEATURE feat = CharDesc->FeatureSets[Type]->Features[i];
Expand Down
2 changes: 1 addition & 1 deletion lstm/networkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void NetworkIO::FromPixes(const StaticShape& shape,
stride_map_.SetStride(h_w_pairs);
ResizeToMap(int_mode(), stride_map_, shape.depth());
// Iterate over the images again to copy the data.
for (int b = 0; b < pixes.size(); ++b) {
for (size_t b = 0; b < pixes.size(); ++b) {
Pix* pix = const_cast<Pix*>(pixes[b]);
float black = 0.0f, white = 255.0f;
if (shape.depth() != 3) ComputeBlackWhite(pix, &black, &white);
Expand Down
3 changes: 2 additions & 1 deletion lstm/stridemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ bool StrideMap::Index::IsLast(FlexDimensions dimension) const {
int StrideMap::Index::MaxIndexOfDim(FlexDimensions dim) const {
int max_index = stride_map_->shape_[dim] - 1;
if (dim == FD_BATCH) return max_index;
int batch = indices_[FD_BATCH];
assert(0 <= indices_[FD_BATCH]);
const size_t batch = indices_[FD_BATCH];
if (dim == FD_HEIGHT) {
if (batch >= stride_map_->heights_.size() ||
stride_map_->heights_[batch] > max_index)
Expand Down
2 changes: 2 additions & 0 deletions textord/textord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ void Textord::TextordPage(PageSegMode pageseg_mode, const FCOORD& reskew,
// RAW_LINE, SINGLE_LINE, SINGLE_WORD and SINGLE_CHAR all need a single row.
gradient = make_single_row(page_tr_, pageseg_mode != PSM_RAW_LINE,
to_block, to_blocks);
} else {
gradient = 0.0f;
}
BaselineDetect baseline_detector(textord_baseline_debug,
reskew, to_blocks);
Expand Down
34 changes: 17 additions & 17 deletions training/boxchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void BoxChar::AddBox(int x, int y, int width, int height) {
/* static */
void BoxChar::TranslateBoxes(int xshift, int yshift,
std::vector<BoxChar*>* boxes) {
for (int i = 0; i < boxes->size(); ++i) {
for (size_t i = 0; i < boxes->size(); ++i) {
BOX* box = (*boxes)[i]->box_;
if (box != nullptr) {
box->x += xshift;
Expand All @@ -68,8 +68,8 @@ void BoxChar::PrepareToWrite(std::vector<BoxChar*>* boxes) {
bool vertical_rules = MostlyVertical(*boxes);
InsertNewlines(rtl_rules, vertical_rules, boxes);
InsertSpaces(rtl_rules, vertical_rules, boxes);
for (int i = 0; i < boxes->size(); ++i) {
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %d\n", i);
for (unsigned int i = 0; i < boxes->size(); ++i) {
if ((*boxes)[i]->box_ == nullptr) tprintf("Null box at index %u\n", i);
}
if (rtl_rules) {
ReorderRTLText(boxes);
Expand All @@ -82,16 +82,16 @@ void BoxChar::InsertNewlines(bool rtl_rules, bool vertical_rules,
std::vector<BoxChar*>* boxes) {
int prev_i = -1;
int max_shift = 0;
for (int i = 0; i < boxes->size(); ++i) {
for (int i = 0; static_cast<unsigned int>(i) < boxes->size(); ++i) {
Box* box = (*boxes)[i]->box_;
if (box == nullptr) {
if (prev_i < 0 || prev_i < i - 1 || i + 1 == boxes->size()) {
if (prev_i < 0 || prev_i < i - 1 || static_cast<unsigned int>(i) + 1 == boxes->size()) {
// Erase null boxes at the start of a line and after another null box.
do {
delete (*boxes)[i];
boxes->erase(boxes->begin() + i);
--i;
} while (i >= 0 && i + 1 == boxes->size() &&
} while (i >= 0 && static_cast<unsigned int>(i) + 1 == boxes->size() &&
(*boxes)[i]->box_ == nullptr);
}
continue;
Expand Down Expand Up @@ -146,7 +146,7 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
std::vector<BoxChar*>* boxes) {
// After InsertNewlines, any remaining null boxes are not newlines, and are
// singletons, so add a box to each remaining null box.
for (int i = 1; i + 1 < boxes->size(); ++i) {
for (int i = 1; static_cast<unsigned int>(i) + 1 < boxes->size(); ++i) {
Box* box = (*boxes)[i]->box_;
if (box == nullptr) {
Box* prev = (*boxes)[i - 1]->box_;
Expand Down Expand Up @@ -178,8 +178,8 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
}
// Left becomes the max right of all next boxes forward to the first
// space or newline.
for (int j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != nullptr &&
(*boxes)[j]->ch_ != "\t";
for (size_t j = i + 2; j < boxes->size() && (*boxes)[j]->box_ != nullptr &&
(*boxes)[j]->ch_ != "\t";
++j) {
next = (*boxes)[j]->box_;
if (next->x + next->w > left) {
Expand All @@ -203,8 +203,8 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
// After adding newlines and spaces, this task is simply a matter of sorting
// by left each group of boxes between newlines.
BoxCharPtrSort sorter;
int end = 0;
for (int start = 0; start < boxes->size(); start = end + 1) {
size_t end = 0;
for (size_t start = 0; start < boxes->size(); start = end + 1) {
end = start + 1;
while (end < boxes->size() && (*boxes)[end]->ch_ != "\t") ++end;
std::sort(boxes->begin() + start, boxes->begin() + end, sorter);
Expand All @@ -215,13 +215,13 @@ void BoxChar::ReorderRTLText(std::vector<BoxChar*>* boxes) {
/* static */
bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar*>& boxes) {
int num_rtl = 0, num_ltr = 0;
for (int i = 0; i < boxes.size(); ++i) {
for (unsigned int i = 0; i < boxes.size(); ++i) {
// Convert the unichar to UTF32 representation
GenericVector<char32> uni_vector;
if (!UNICHAR::UTF8ToUnicode(boxes[i]->ch_.c_str(), &uni_vector)) {
tprintf("Illegal utf8 in boxchar %d string:%s = ", i,
tprintf("Illegal utf8 in boxchar %u string:%s = ", i,
boxes[i]->ch_.c_str());
for (int c = 0; c < boxes[i]->ch_.size(); ++c) {
for (size_t c = 0; c < boxes[i]->ch_.size(); ++c) {
tprintf(" 0x%x", boxes[i]->ch_[c]);
}
tprintf("\n");
Expand All @@ -244,7 +244,7 @@ bool BoxChar::ContainsMostlyRTL(const std::vector<BoxChar*>& boxes) {
/* static */
bool BoxChar::MostlyVertical(const std::vector<BoxChar*>& boxes) {
inT64 total_dx = 0, total_dy = 0;
for (int i = 1; i < boxes.size(); ++i) {
for (size_t i = 1; i < boxes.size(); ++i) {
if (boxes[i - 1]->box_ != nullptr && boxes[i]->box_ != nullptr &&
boxes[i - 1]->page_ == boxes[i]->page_) {
int dx = boxes[i]->box_->x - boxes[i - 1]->box_->x;
Expand All @@ -263,7 +263,7 @@ bool BoxChar::MostlyVertical(const std::vector<BoxChar*>& boxes) {
/* static */
int BoxChar::TotalByteLength(const std::vector<BoxChar*>& boxes) {
int total_length = 0;
for (int i = 0; i < boxes.size(); ++i) total_length += boxes[i]->ch_.size();
for (size_t i = 0; i < boxes.size(); ++i) total_length += boxes[i]->ch_.size();
return total_length;
}

Expand Down Expand Up @@ -302,7 +302,7 @@ string BoxChar::GetTesseractBoxStr(int height,
const std::vector<BoxChar*>& boxes) {
string output;
char buffer[kMaxLineLength];
for (int i = 0; i < boxes.size(); ++i) {
for (size_t i = 0; i < boxes.size(); ++i) {
const Box* box = boxes[i]->box_;
if (box == nullptr) {
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
Expand Down
8 changes: 5 additions & 3 deletions training/commontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "tprintf.h"
#include "unicity_table.h"

#include <assert.h>
#include <math.h>

using tesseract::CCUtil;
Expand Down Expand Up @@ -368,8 +369,9 @@ void ReadTrainingSamples(const FEATURE_DEFS_STRUCT& feature_defs,
LABELEDLIST char_sample;
FEATURE_SET feature_samples;
CHAR_DESC char_desc;
int i;
int feature_type = ShortNameToFeatureType(feature_defs, feature_name);
int ShortNameToFeatureType_res = ShortNameToFeatureType(feature_defs, feature_name);
assert(0 <= ShortNameToFeatureType_res);
unsigned int feature_type = static_cast<unsigned int>(ShortNameToFeatureType_res);
// Zero out the font_sample_count for all the classes.
LIST it = *training_samples;
iterate(it) {
Expand Down Expand Up @@ -404,7 +406,7 @@ void ReadTrainingSamples(const FEATURE_DEFS_STRUCT& feature_defs,
} else {
FreeFeatureSet(feature_samples);
}
for (i = 0; i < char_desc->NumFeatureSets; i++) {
for (size_t i = 0; i < char_desc->NumFeatureSets; i++) {
if (feature_type != i)
FreeFeatureSet(char_desc->FeatureSets[i]);
}
Expand Down
4 changes: 0 additions & 4 deletions training/lstmtraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ int main(int argc, char **argv) {
return 1;
}

bool best_dumped = true;
char* best_model_dump = nullptr;
size_t best_model_size = 0;
STRING best_model_name;
tesseract::LSTMTester tester(static_cast<inT64>(FLAGS_max_image_MB) *
1048576);
tesseract::TestCallback tester_callback = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions training/normstrngs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "normstrngs.h"

#include <assert.h>
#include "icuerrorcode.h"
#include "unichar.h"
#include "unicode/normalizer2.h" // From libicu
Expand Down Expand Up @@ -181,7 +182,13 @@ bool IsWhitespace(const char32 ch) {
}

bool IsUTF8Whitespace(const char* text) {
#if 0 // intent
return SpanUTF8Whitespace(text) == strlen(text);
#else // avoiding g++ -Wsign-compare warning
const int res = SpanUTF8Whitespace(text);
assert(0 <= res);
return static_cast<unsigned int>(res) == strlen(text);
#endif
}

int SpanUTF8Whitespace(const char* text) {
Expand Down
Loading