Skip to content

Commit 637be53

Browse files
authored
Merge pull request #4174 from stweil/warnings
Fix some compiler warnings and avoid unnecessary conversions from std::string to char pointer
2 parents ea0b245 + 4a6efcd commit 637be53

File tree

7 files changed

+20
-26
lines changed

7 files changed

+20
-26
lines changed

src/ccstruct/boxread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ FILE *OpenBoxFile(const char *fname) {
7676
bool ReadAllBoxes(int target_page, bool skip_blanks, const char *filename, std::vector<TBOX> *boxes,
7777
std::vector<std::string> *texts, std::vector<std::string> *box_texts,
7878
std::vector<int> *pages) {
79-
std::ifstream input(BoxFileName(filename).c_str(), std::ios::in | std::ios::binary);
79+
std::ifstream input(BoxFileName(filename), std::ios::in | std::ios::binary);
8080
if (input.fail()) {
8181
tprintf("Cannot read box data from '%s'.\n", BoxFileName(filename).c_str());
8282
tprintf("Does it exists?\n");

src/textord/pithsync.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,7 @@ double check_pitch_sync2( // find segmentation
316316
TBOX this_box; // bounding box
317317
TBOX next_box; // box of next blob
318318
FPSEGPT *segpt; // segment point
319-
double best_cost; // best path
320319
double mean_sum; // computes result
321-
FPCUTPT *best_end; // end of best path
322320
int16_t best_fake; // best fake level
323321
int16_t best_count; // no of cuts
324322
BLOBNBOX_IT this_it; // copy iterator
@@ -371,8 +369,6 @@ double check_pitch_sync2( // find segmentation
371369
}
372370

373371
this_it = *blob_it;
374-
best_cost = FLT_MAX;
375-
best_end = nullptr;
376372
this_box = box_next(&this_it); // first box
377373
next_box = box_next(&this_it); // second box
378374
blob_index = 1;
@@ -411,7 +407,8 @@ double check_pitch_sync2( // find segmentation
411407
}
412408

413409
best_fake = INT16_MAX;
414-
best_cost = INT32_MAX;
410+
// best path
411+
double best_cost = INT32_MAX;
415412
best_count = INT16_MAX;
416413
while (x < right_edge + pitch) {
417414
offset = x < right_edge ? right_edge - x : 0;
@@ -438,7 +435,8 @@ double check_pitch_sync2( // find segmentation
438435
}
439436
ASSERT_HOST(best_fake < INT16_MAX);
440437

441-
best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
438+
// end of best path
439+
FPCUTPT *best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
442440
if (this_box.right() == textord_test_x && this_box.top() == textord_test_y) {
443441
for (x = left_edge - pitch; x < right_edge + pitch; x++) {
444442
tprintf("x=%d, C=%g, s=%g, sq=%g, prev=%d\n", x, cutpts[x - array_origin].cost_function(),
@@ -509,9 +507,7 @@ double check_pitch_sync3( // find segmentation
509507
FPSEGPT *segpt; // segment point
510508
int minindex; // next input position
511509
int test_index; // index to mins
512-
double best_cost; // best path
513510
double mean_sum; // computes result
514-
FPCUTPT *best_end; // end of best path
515511
int16_t best_fake; // best fake level
516512
int16_t best_count; // no of cuts
517513
FPSEGPT_IT seg_it = seg_list; // output iterator
@@ -549,8 +545,6 @@ double check_pitch_sync3( // find segmentation
549545
offset);
550546
}
551547

552-
best_cost = FLT_MAX;
553-
best_end = nullptr;
554548
for (offset = -pitch_error, minindex = 0; offset < pitch_error; offset++, minindex++) {
555549
mins[minindex] = projection->local_min(x + offset);
556550
}
@@ -629,7 +623,8 @@ double check_pitch_sync3( // find segmentation
629623
}
630624

631625
best_fake = INT16_MAX;
632-
best_cost = INT32_MAX;
626+
// best path
627+
double best_cost = INT32_MAX;
633628
best_count = INT16_MAX;
634629
while (x < right_edge + pitch) {
635630
offset = x < right_edge ? right_edge - x : 0;
@@ -656,7 +651,8 @@ double check_pitch_sync3( // find segmentation
656651
}
657652
ASSERT_HOST(best_fake < INT16_MAX);
658653

659-
best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
654+
// end of best path
655+
FPCUTPT *best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
660656
// for (x=left_edge-pitch;x<right_edge+pitch;x++)
661657
// {
662658
// tprintf("x=%d, C=%g, s=%g, sq=%g, prev=%d\n",

src/textord/tospace.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,8 @@ void Textord::row_spacing_stats(TO_ROW *row, GAPMAP *gapmap, int16_t block_idx,
283283
int16_t gap_width;
284284
int16_t real_space_threshold = 0;
285285
int16_t max = 0;
286-
int16_t index;
287286
int16_t large_gap_count = 0;
288287
bool suspected_table;
289-
int32_t max_max_nonspace; // upper bound
290288
bool good_block_space_estimate = block_space_gap_width > 0;
291289
int32_t end_of_row;
292290
int32_t row_length = 0;
@@ -479,11 +477,12 @@ number of samples can be taken as certain kerns.
479477
below the threshold.
480478
*/
481479

482-
max_max_nonspace = int32_t((row->space_threshold + row->kern_size) / 2);
480+
// upper bound
481+
int32_t max_max_nonspace = int32_t((row->space_threshold + row->kern_size) / 2);
483482

484483
// default
485484
row->max_nonspace = max_max_nonspace;
486-
for (index = 0; index <= max_max_nonspace; index++) {
485+
for (int32_t index = 0; index <= max_max_nonspace; index++) {
487486
if (all_gap_stats.pile_count(index) > max) {
488487
max = all_gap_stats.pile_count(index);
489488
}

src/textord/underlin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ void vertical_cunderline_projection( // project outlines
211211
ICOORD pos; // current point
212212
ICOORD step; // edge step
213213
int16_t lower_y, upper_y; // region limits
214-
int32_t length; // of outline
215-
int16_t stepindex; // current step
216214
C_OUTLINE_IT out_it = outline->child();
217215

218216
pos = outline->start_pos();
219-
length = outline->pathlength();
220-
for (stepindex = 0; stepindex < length; stepindex++) {
217+
int16_t length = outline->pathlength();
218+
for (int16_t stepindex = 0; stepindex < length; stepindex++) {
221219
step = outline->step(stepindex);
222220
if (step.x() > 0) {
223221
lower_y = static_cast<int16_t>(floor(baseline->y(pos.x()) + baseline_offset + 0.5));

src/training/lstmtraining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int main(int argc, char **argv) {
9292
}
9393

9494
// Check write permissions.
95-
std::string test_file = FLAGS_model_output.c_str();
95+
std::string test_file = FLAGS_model_output;
9696
test_file += "_wtest";
9797
FILE *f = fopen(test_file.c_str(), "wb");
9898
if (f != nullptr) {
@@ -107,10 +107,10 @@ int main(int argc, char **argv) {
107107
}
108108

109109
// Setup the trainer.
110-
std::string checkpoint_file = FLAGS_model_output.c_str();
110+
std::string checkpoint_file = FLAGS_model_output;
111111
checkpoint_file += "_checkpoint";
112112
std::string checkpoint_bak = checkpoint_file + ".bak";
113-
tesseract::LSTMTrainer trainer(FLAGS_model_output.c_str(), checkpoint_file.c_str(),
113+
tesseract::LSTMTrainer trainer(FLAGS_model_output, checkpoint_file,
114114
FLAGS_debug_interval,
115115
static_cast<int64_t>(FLAGS_max_image_MB) * 1048576);
116116
if (!trainer.InitCharSet(FLAGS_traineddata.c_str())) {

src/training/unicharset/lstmtrainer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ LSTMTrainer::LSTMTrainer()
8080
debug_interval_ = 0;
8181
}
8282

83-
LSTMTrainer::LSTMTrainer(const char *model_base, const char *checkpoint_name,
83+
LSTMTrainer::LSTMTrainer(const std::string &model_base, const std::string &checkpoint_name,
8484
int debug_interval, int64_t max_memory)
8585
: randomly_rotate_(false),
8686
training_data_(max_memory),

src/training/unicharset/lstmtrainer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ using TestCallback = std::function<std::string(int, const double *,
8484
class TESS_UNICHARSET_TRAINING_API LSTMTrainer : public LSTMRecognizer {
8585
public:
8686
LSTMTrainer();
87-
LSTMTrainer(const char *model_base, const char *checkpoint_name,
87+
LSTMTrainer(const std::string &model_base,
88+
const std::string &checkpoint_name,
8889
int debug_interval, int64_t max_memory);
8990
virtual ~LSTMTrainer();
9091

0 commit comments

Comments
 (0)