Skip to content

Commit

Permalink
Fix issues reported by Coverity Scan (#1409)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
stweil authored and zdenop committed Mar 22, 2018
1 parent 1694be9 commit 660b366
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/pdfrenderer.cpp
Expand Up @@ -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)) {
Expand Down
6 changes: 5 additions & 1 deletion ccutil/serialis.cpp
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions textord/baselinedetect.cpp
Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion textord/colpartitionset.cpp
Expand Up @@ -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;
}
Expand Down
24 changes: 13 additions & 11 deletions viewer/svutil.cpp
Expand Up @@ -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);
for (;;) {
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
addr_info->ai_protocol);
if (stream_ >= 0) {
if (connect(stream_, addr_info->ai_addr, addr_info->ai_addrlen) == 0) {
break;
}

while (connect(stream_, addr_info->ai_addr,
addr_info->ai_addrlen) < 0) {
std::cout << "ScrollView: Waiting for server...\n";
Close();

std::cout << "ScrollView: Waiting for server...\n";
#ifdef _WIN32
Sleep(1000);
Sleep(1000);
#else
sleep(1);
sleep(1);
#endif

Close();
stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
addr_info->ai_protocol);
}
}
}
FreeAddrInfo(addr_info);
Expand Down

0 comments on commit 660b366

Please sign in to comment.