1
0
Fork 0

fixed issues reported by coverity scan

This commit is contained in:
jsteemann 2017-01-24 11:31:40 +01:00
parent 344bcd8ea6
commit db80ce4d1b
2 changed files with 8 additions and 14 deletions

View File

@ -444,7 +444,7 @@ struct hash<arangodb::basics::VPackHashedSlice> {
template <> template <>
struct equal_to<arangodb::basics::VPackHashedSlice> { struct equal_to<arangodb::basics::VPackHashedSlice> {
bool operator()(arangodb::basics::VPackHashedSlice const& lhs, bool operator()(arangodb::basics::VPackHashedSlice const& lhs,
arangodb::basics::VPackHashedSlice const& rhs) const noexcept { arangodb::basics::VPackHashedSlice const& rhs) const {
return lhs.slice.equals(rhs.slice); return lhs.slice.equals(rhs.slice);
} }
}; };

View File

@ -42,8 +42,8 @@ namespace options {
template <typename T> template <typename T>
inline typename std::enable_if<std::is_signed<T>::value, T>::type toNumber( inline typename std::enable_if<std::is_signed<T>::value, T>::type toNumber(
std::string const& value) { std::string const& value) {
auto v = static_cast<T>(std::stoll(value)); auto v = static_cast<int64_t>(std::stoll(value));
if (v < (std::numeric_limits<T>::min)() || v > (std::numeric_limits<T>::max)()) { if (v < static_cast<int64_t>((std::numeric_limits<T>::min)()) || v > static_cast<int64_t>((std::numeric_limits<T>::max)())) {
throw std::out_of_range(value); throw std::out_of_range(value);
} }
return static_cast<T>(v); return static_cast<T>(v);
@ -53,8 +53,8 @@ inline typename std::enable_if<std::is_signed<T>::value, T>::type toNumber(
template <typename T> template <typename T>
inline typename std::enable_if<std::is_unsigned<T>::value, T>::type toNumber( inline typename std::enable_if<std::is_unsigned<T>::value, T>::type toNumber(
std::string const& value) { std::string const& value) {
auto v = static_cast<T>(std::stoull(value)); auto v = static_cast<uint64_t>(std::stoull(value));
if (v < (std::numeric_limits<T>::min)() || v > (std::numeric_limits<T>::max)()) { if (v < static_cast<uint64_t>((std::numeric_limits<T>::min)()) || v > static_cast<uint64_t>((std::numeric_limits<T>::max)())) {
throw std::out_of_range(value); throw std::out_of_range(value);
} }
return static_cast<T>(v); return static_cast<T>(v);
@ -210,15 +210,11 @@ struct NumericParameter : public Parameter {
std::string set(std::string const& value) override { std::string set(std::string const& value) override {
try { try {
ValueType v = toNumber<ValueType>(value); ValueType v = toNumber<ValueType>(value);
if (v >= (std::numeric_limits<T>::min)() && *ptr = v;
v <= (std::numeric_limits<T>::max)()) { return "";
*ptr = v;
return "";
}
} catch (...) { } catch (...) {
return "invalid numeric value"; return "invalid numeric value";
} }
return "number out of range";
} }
void toVPack(VPackBuilder& builder) const override { void toVPack(VPackBuilder& builder) const override {
@ -291,9 +287,7 @@ struct BoundedParameter : public T {
std::string set(std::string const& value) override { std::string set(std::string const& value) override {
try { try {
typename T::ValueType v = toNumber<typename T::ValueType>(value); typename T::ValueType v = toNumber<typename T::ValueType>(value);
if (v >= (std::numeric_limits<typename T::ValueType>::min)() && if (v >= minValue && v <= maxValue) {
v <= (std::numeric_limits<typename T::ValueType>::max)() && v >= minValue &&
v <= maxValue) {
*this->ptr = v; *this->ptr = v;
return ""; return "";
} }