Skip to content
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

nit: Fixes some compiler warnings #2599

Merged
merged 4 commits into from
Sep 15, 2020
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
2 changes: 1 addition & 1 deletion src/meili/map_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace {
using namespace valhalla;
using namespace valhalla::meili;

constexpr float MAX_ACCUMULATED_COST = 99999999;
constexpr float MAX_ACCUMULATED_COST = 99999999.f;

inline float GreatCircleDistanceSquared(const Measurement& left, const Measurement& right) {
return left.lnglat().DistanceSquared(right.lnglat());
Expand Down
12 changes: 6 additions & 6 deletions test/double_bucket_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TryAddRemove(const std::vector<uint32_t>& costs, const std::vector<uint32_t
expected = (uint32_t)(float)expected;
uint32_t labelindex = adjlist.pop();
auto edgelabel = 0;
if (labelindex != kInvalidLabel) {
if (labelindex != baldr::kInvalidLabel) {
edgelabel = edgelabels[labelindex];
}
EXPECT_EQ(edgelabel, expected) << "TryAddRemove: expected order test failed";
Expand Down Expand Up @@ -70,7 +70,7 @@ void TryClear(const std::vector<uint32_t>& costs) {
}
adjlist.clear();
uint32_t idx = adjlist.pop();
EXPECT_EQ(idx, kInvalidLabel) << "TryClear: failed to return invalid edge index after Clear";
EXPECT_EQ(idx, baldr::kInvalidLabel) << "TryClear: failed to return invalid edge index after Clear";
}

TEST(DoubleBucketQueue, TestClear) {
Expand Down Expand Up @@ -104,16 +104,16 @@ void TryRemove(DoubleBucketQueue& dbqueue, size_t num_to_remove, const std::vect
auto previous_cost = -std::numeric_limits<float>::infinity();
for (size_t i = 0; i < num_to_remove; ++i) {
const auto top = dbqueue.pop();
EXPECT_NE(top, kInvalidLabel) << "TryAddRemove: expected " + std::to_string(num_to_remove) +
" labels to remove";
EXPECT_NE(top, baldr::kInvalidLabel)
<< "TryAddRemove: expected " + std::to_string(num_to_remove) + " labels to remove";
const auto cost = costs[top];
EXPECT_LE(previous_cost, cost) << "TryAddRemove: expected order test failed";
previous_cost = cost;
}

{
const auto top = dbqueue.pop();
EXPECT_EQ(top, kInvalidLabel) << "Simulation: expect list to be empty";
EXPECT_EQ(top, baldr::kInvalidLabel) << "Simulation: expect list to be empty";
}
}

Expand All @@ -132,7 +132,7 @@ void TrySimulation(DoubleBucketQueue& dbqueue,
std::mt19937 gen(rd());
for (size_t i = 0; i < loop_count; i++) {
const auto key = dbqueue.pop();
if (key == kInvalidLabel) {
if (key == baldr::kInvalidLabel) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion test/gurka/gurka.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ nodelayout map_to_coordinates(const std::string& map,
// In-place remove leading whitespace from each line
for (auto& line : lines) {
// This must be a blank line or something
if (line.size() < min_whitespace)
if (line.size() < static_cast<size_t>(min_whitespace))
continue;
line.erase(line.begin(), line.begin() + min_whitespace);
}
Expand Down
7 changes: 3 additions & 4 deletions valhalla/baldr/double_bucket_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define VALHALLA_BALDR_DOUBLE_BUCKET_QUEUE_H_

#include <algorithm>
#include <baldr/graphconstants.h>
#include <cmath>
#include <cstdint>
#include <valhalla/midgard/util.h>
Expand All @@ -10,8 +11,6 @@
namespace valhalla {
namespace baldr {

constexpr uint32_t kInvalidLabel = std::numeric_limits<uint32_t>::max();

/**
* A callable element which returns the cost for a label.
*/
Expand Down Expand Up @@ -136,13 +135,13 @@ class DoubleBucketQueue final {
// Reset currentbucket to the last bucket - in case another access of
// adjacency list is done.
currentbucket_--;
return kInvalidLabel;
return baldr::kInvalidLabel;
} else {
// Move labels from the overflow bucket to the low level buckets.
// Return invalid label if still empty.
empty_overflow();
if (empty()) {
return kInvalidLabel;
return baldr::kInvalidLabel;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions valhalla/baldr/graphconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ constexpr uint32_t kMaxGraphTileId = 4194303;
// Maximum id/index within a tile. 21 bits
constexpr uint32_t kMaxGraphId = 2097151;

// Invalid edge label
constexpr uint32_t kInvalidLabel = std::numeric_limits<uint32_t>::max();

// A value to use for invalid latitude/longitudes (i.e. uninitialized)
constexpr float kInvalidLatitude = std::numeric_limits<float>::max();
constexpr float kInvalidLongitude = std::numeric_limits<float>::max();
Expand Down
2 changes: 1 addition & 1 deletion valhalla/baldr/tilegetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class tile_getter_t {
* Allows users to interrupt downloading requests.
* Returns true if the request should be interrupted.
*/
virtual void set_interrupt(const interrupt_t* interrupt){};
virtual void set_interrupt(const interrupt_t*){};

virtual ~tile_getter_t() = default;
};
Expand Down
12 changes: 6 additions & 6 deletions valhalla/baldr/time_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct TimeInfo {
int default_timezone_index = baldr::DateTime::get_tz_db().to_index("Etc/UTC")) {
// No time to to track
if (!location.has_date_time()) {
return {false, 0, 0, kConstrainedFlowSecondOfDay};
return {false, 0, 0, kConstrainedFlowSecondOfDay, 0, false, nullptr};
}

// Find the first edge whose end node has a valid timezone index and keep it
Expand Down Expand Up @@ -101,7 +101,7 @@ struct TimeInfo {
int default_timezone_index = baldr::DateTime::get_tz_db().to_index("Etc/UTC")) {
// No time to to track
if (date_time.empty()) {
return {false, 0, 0, kConstrainedFlowSecondOfDay};
return {false, 0, 0, kConstrainedFlowSecondOfDay, 0, false, nullptr};
}

// Set the origin timezone to be the timezone at the end node use this for timezone changes
Expand Down Expand Up @@ -132,7 +132,7 @@ struct TimeInfo {
parsed_date = dt::get_formatted_date(date_time, true);
} catch (...) {
LOG_ERROR("Could not parse provided date_time: " + date_time);
return {false, 0, 0, kConstrainedFlowSecondOfDay};
return {false, 0, 0, kConstrainedFlowSecondOfDay, 0, false, nullptr};
}
const auto then_date = date::make_zoned(tz, parsed_date);
uint64_t local_time = date::to_utc_time(then_date.get_sys_time()).time_since_epoch().count();
Expand Down Expand Up @@ -180,7 +180,7 @@ struct TimeInfo {
if (sw < 0) {
sw += valhalla::midgard::kSecondsPerWeek;
} // wrap the week second if it went past the end
else if (sw > valhalla::midgard::kSecondsPerWeek) {
else if (sw > static_cast<int32_t>(valhalla::midgard::kSecondsPerWeek)) {
sw -= valhalla::midgard::kSecondsPerWeek;
}

Expand Down Expand Up @@ -227,7 +227,7 @@ struct TimeInfo {
if (sw < 0) {
sw += valhalla::midgard::kSecondsPerWeek;
} // wrap the week second if it went past the end
else if (sw > valhalla::midgard::kSecondsPerWeek) {
else if (sw > static_cast<int32_t>(valhalla::midgard::kSecondsPerWeek)) {
sw -= valhalla::midgard::kSecondsPerWeek;
}

Expand Down Expand Up @@ -265,4 +265,4 @@ struct TimeInfo {
};

} // namespace baldr
} // namespace valhalla
} // namespace valhalla
2 changes: 0 additions & 2 deletions valhalla/meili/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ constexpr uint16_t kInvalidDestination = std::numeric_limits<uint16_t>::max();
class Label : public sif::EdgeLabel {
public:
Label() {
// zero out the data but set the node Id and edge Id to invalid
memset(this, 0, sizeof(Label));
Copy link
Contributor Author

@purew purew Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous as Label is a child of EdgeLabel, meaning that there could be a vtable which this memset would overwrite. I'm not sure what the memset intends to do since this being the constructor, the fields should already be zero'd.

cc @dnesbitt61

Copy link
Member

@kevinkreiser kevinkreiser Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree this looks dangerous but it looks like the default constructor for EdgeLabel doesnt zero them out though..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed more with @kevinkreiser and the safest solution is probably to initialize the values in the EdgeLabel constructor

nodeid_ = baldr::GraphId();
edgeid_ = baldr::GraphId();
predecessor_ = baldr::kInvalidLabel;
Expand Down
4 changes: 2 additions & 2 deletions valhalla/meili/topk_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class EnlargedViterbiSearch {
: vs_(vs), claim_stateid_(claim_stateid),
original_emission_cost_model_(vs.emission_cost_model()),
original_transition_cost_model_(vs.transition_cost_model()), origin_(), clone_(),
clone_start_time_(kInvalidTime), clone_end_time_(kInvalidTime),
initial_origins_(initial_origins), removed_origins_(removed_origins) {
initial_origins_(initial_origins), removed_origins_(removed_origins),
clone_start_time_(kInvalidTime), clone_end_time_(kInvalidTime) {
vs_.set_emission_cost_model(EnlargedEmissionCostModel(*this));
vs_.set_transition_cost_model(EnlargedTransitionCostModel(*this));
}
Expand Down
4 changes: 2 additions & 2 deletions valhalla/meili/transition_cost_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class TransitionCostModel {
float CalculateTransitionCost(float turn_cost,
float route_distance,
float measurement_distance,
float route_time,
float measurement_time) const {
float,
float) const {
return (turn_cost + std::abs(route_distance - measurement_distance)) * inv_beta_;
}

Expand Down
8 changes: 3 additions & 5 deletions valhalla/midgard/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ template <class T> class sequence {
// sort the file based on the predicate
void sort(const std::function<bool(const T&, const T&)>& predicate,
size_t buffer_size = 1024 * 1024 * 512 / sizeof(T)) {
using queue_t =
std::map<T, std::list<std::fstream>::iterator, std::function<bool(const T&, const T&)>>;

flush();
// if no elements we are done
if (memmap.size() == 0) {
Expand Down Expand Up @@ -570,9 +567,10 @@ struct tar {
// make a copy and blank the checksum
header_t temp = *this;
memset(temp.chksum, ' ', 8);
int64_t usum = 0, sum = 0;
purew marked this conversation as resolved.
Show resolved Hide resolved
int64_t sum = 0;
uint64_t usum = 0;
// compute the checksum
for (int i = 0; i < sizeof(header_t); i++) {
for (int i = 0; static_cast<size_t>(i) < sizeof(header_t); i++) {
usum += ((unsigned char*)&temp)[i];
sum += ((char*)&temp)[i];
}
Expand Down
12 changes: 9 additions & 3 deletions valhalla/sif/edgelabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class EdgeLabel {
/**
* Default constructor.
*/
EdgeLabel() {
EdgeLabel()
: predecessor_(baldr::kInvalidLabel), path_distance_(0), restrictions_(0),
edgeid_(baldr::kInvalidGraphId), opp_index_(0), opp_local_idx_(0), mode_(0),
endnode_(baldr::kInvalidGraphId), use_(0), classification_(0), shortcut_(0), dest_only_(0),
origin_(0), toll_(0), not_thru_(0), deadend_(0), on_complex_rest_(0), restriction_idx_(0),
cost_(0, 0), sortcost_(0), distance_(0), transition_cost_(0, 0) {
}

/**
Expand Down Expand Up @@ -56,13 +61,14 @@ class EdgeLabel {
: predecessor_(predecessor), path_distance_(path_distance), restrictions_(edge->restrictions()),
edgeid_(edgeid), opp_index_(edge->opp_index()), opp_local_idx_(edge->opp_local_idx()),
mode_(static_cast<uint32_t>(mode)), endnode_(edge->endnode()),
restriction_idx_(restriction_idx), use_(static_cast<uint32_t>(edge->use())),
use_(static_cast<uint32_t>(edge->use())),
classification_(static_cast<uint32_t>(edge->classification())), shortcut_(edge->shortcut()),
dest_only_(edge->destonly()), origin_(0), toll_(edge->toll()), not_thru_(edge->not_thru()),
deadend_(edge->deadend()),
on_complex_rest_(edge->part_of_complex_restriction() || edge->start_restriction() ||
edge->end_restriction()),
cost_(cost), sortcost_(sortcost), distance_(dist), transition_cost_(transition_cost) {
restriction_idx_(restriction_idx), cost_(cost), sortcost_(sortcost), distance_(dist),
transition_cost_(transition_cost) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion valhalla/thor/astarheuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AStarHeuristic {
/**
* Constructor.
*/
AStarHeuristic() : costfactor_(1.0f), distapprox_({}) {
AStarHeuristic() : distapprox_({}), costfactor_(1.0f) {
}

/**
Expand Down
10 changes: 5 additions & 5 deletions valhalla/thor/dijkstras.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class Dijkstras {

protected:
// A child-class must implement this to learn about what nodes were expanded
virtual void ExpandingNode(baldr::GraphReader& graphreader,
const baldr::GraphTile* tile,
const baldr::NodeInfo* node,
const sif::EdgeLabel& current,
const sif::EdgeLabel* previous){};
virtual void ExpandingNode(baldr::GraphReader&,
purew marked this conversation as resolved.
Show resolved Hide resolved
const baldr::GraphTile*,
const baldr::NodeInfo*,
const sif::EdgeLabel&,
const sif::EdgeLabel*) = 0;

// A child-class must implement this to decide when to stop the expansion
virtual ExpansionRecommendation ShouldExpand(baldr::GraphReader& graphreader,
Expand Down