Don't crash on assigning nil to a string in lua
This commit is contained in:
committed by
Patrick Niklaus
parent
844300b95a
commit
3bade8625f
@@ -13,6 +13,21 @@ namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
inline void maybeSetString(std::string &str, const char* value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
str = std::string(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This struct is the direct result of the call to ```way_function```
|
||||
@@ -50,6 +65,20 @@ struct ExtractionWay
|
||||
void set_backward_mode(const TravelMode m) { backward_travel_mode = m; }
|
||||
TravelMode get_backward_mode() const { return backward_travel_mode; }
|
||||
|
||||
// wrappers to allow assigning nil (nullptr) to string values
|
||||
void SetName(const char* value) { detail::maybeSetString(name, value); }
|
||||
const char* GetName() const { return name.c_str(); }
|
||||
void SetRef(const char* value) { detail::maybeSetString(ref, value); }
|
||||
const char* GetRef() const { return ref.c_str(); }
|
||||
void SetDestinations(const char* value) { detail::maybeSetString(destinations, value); }
|
||||
const char* GetDestinations() const { return destinations.c_str(); }
|
||||
void SetPronunciation(const char* value) { detail::maybeSetString(pronunciation, value); }
|
||||
const char* GetPronunciation() const { return pronunciation.c_str(); }
|
||||
void SetTurnLanesForward(const char* value) { detail::maybeSetString(turn_lanes_forward, value); }
|
||||
const char* GetTurnLanesForward() const { return turn_lanes_forward.c_str(); }
|
||||
void SetTurnLanesBackward(const char* value) { detail::maybeSetString(turn_lanes_backward, value); }
|
||||
const char* GetTurnLanesBackward() const { return turn_lanes_backward.c_str(); }
|
||||
|
||||
double forward_speed;
|
||||
double backward_speed;
|
||||
double duration;
|
||||
|
||||
Reference in New Issue
Block a user