Fix issues reported by Coverity Scan (#1409)

* Fix CID 1164532 'Constant' variable guards dead code

Signed-off-by: Stefan Weil <sw@weilnetz.de>

* Fix CID 1164594 Argument cannot be negative

Signed-off-by: Stefan Weil <sw@weilnetz.de>

* Fix CID 1164597 Argument cannot be negative

Signed-off-by: Stefan Weil <sw@weilnetz.de>

* Fix CID 1366447 Argument cannot be negative

Fix also the data type for current_pos, as ftell returns a long value.

Signed-off-by: Stefan Weil <sw@weilnetz.de>

* Fix CID 1270404 Arguments in wrong order

This does not change the code, but should help Coverity Scan to see
that the argument order is as intended.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-03-22 20:00:01 +01:00 committed by zdenop
parent 1694be9223
commit 660b366401
5 changed files with 34 additions and 16 deletions

View File

@ -663,6 +663,10 @@ bool TessPDFRenderer::BeginDocumentHandler() {
}
fseek(fp, 0, SEEK_END);
long int size = ftell(fp);
if (size < 0) {
fclose(fp);
return false;
}
fseek(fp, 0, SEEK_SET);
const std::unique_ptr<char[]> buffer(new char[size]);
if (fread(buffer.get(), 1, size, fp) != static_cast<size_t>(size)) {

View File

@ -64,7 +64,11 @@ bool TFile::Open(const char* data, int size) {
bool TFile::Open(FILE* fp, int64_t end_offset) {
offset_ = 0;
int64_t current_pos = ftell(fp);
long current_pos = ftell(fp);
if (current_pos < 0) {
// ftell failed.
return false;
}
if (end_offset < 0) {
if (fseek(fp, 0, SEEK_END))
return false;

View File

@ -291,7 +291,9 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
double min_dist = MAX_FLOAT32;
double max_dist = -MAX_FLOAT32;
BLOBNBOX_IT blob_it(blobs_);
#ifdef kDebugYCoord
bool debug = false;
#endif
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
BLOBNBOX* blob = blob_it.data();
const TBOX& box = blob->bounding_box();
@ -302,10 +304,12 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
blob->baseline_position());
double offset = direction * blob_pos;
perp_blob_dists.push_back(offset);
#ifdef kDebugYCoord
if (debug) {
tprintf("Displacement %g for blob at:", offset);
box.print();
}
#endif
UpdateRange(offset, &min_dist, &max_dist);
}
// Set up a histogram using disp_quant_factor_ as the bucket size.
@ -316,12 +320,14 @@ void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
}
GenericVector<KDPairInc<float, int> > scaled_modes;
dist_stats.top_n_modes(kMaxDisplacementsModes, &scaled_modes);
#ifdef kDebugYCoord
if (debug) {
for (int i = 0; i < scaled_modes.size(); ++i) {
tprintf("Top mode = %g * %d\n",
scaled_modes[i].key * disp_quant_factor_, scaled_modes[i].data);
}
}
#endif
for (int i = 0; i < scaled_modes.size(); ++i)
displacement_modes_.push_back(disp_quant_factor_ * scaled_modes[i].key);
}

View File

@ -584,7 +584,9 @@ void ColPartitionSet::AccumulateColumnWidthsAndGaps(int* total_width,
++*width_samples;
if (!it.at_last()) {
ColPartition* next_part = it.data_relative(1);
int gap = part->KeyWidth(part->right_key(), next_part->left_key());
int part_left = part->right_key();
int part_right = next_part->left_key();
int gap = part->KeyWidth(part_left, part_right);
*total_gap += gap;
++*gap_samples;
}

View File

@ -425,21 +425,23 @@ SVNetwork::SVNetwork(const char* hostname, int port) {
// Note: There is no exception handling in case the server never turns up.
Close();
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
addr_info->ai_protocol);
while (connect(stream_, addr_info->ai_addr,
addr_info->ai_addrlen) < 0) {
std::cout << "ScrollView: Waiting for server...\n";
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
Close();
for (;;) {
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
addr_info->ai_protocol);
addr_info->ai_protocol);
if (stream_ >= 0) {
if (connect(stream_, addr_info->ai_addr, addr_info->ai_addrlen) == 0) {
break;
}
Close();
std::cout << "ScrollView: Waiting for server...\n";
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
}
}
FreeAddrInfo(addr_info);