Skip to content

Commit 911c5e2

Browse files
authored
improve handling of non-numeric values in isNumber<T> (#168)
* improve handling of non-numeric values in isNumber<T> previously, an exception was thrown and caught when isNumber<T> was called on a non-numeric Slice. now, this exception is avoided and the case is handled with a simple initial value type check instead. * make it more efficient
1 parent 4e7f1f0 commit 911c5e2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

include/velocypack/SliceBase.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ struct SliceBase {
338338
v <= kMax;
339339
}
340340

341-
int64_t v = getInt();
342-
return (v >= static_cast<int64_t>((std::numeric_limits<T>::min)()) &&
343-
v <= static_cast<int64_t>((std::numeric_limits<T>::max)()));
341+
if (isInteger()) {
342+
int64_t v = getInt();
343+
return (v >= static_cast<int64_t>((std::numeric_limits<T>::min)()) &&
344+
v <= static_cast<int64_t>((std::numeric_limits<T>::max)()));
345+
}
346+
return false;
344347
} else {
345348
// unsigned integral type
346349
if (isDouble()) {
@@ -354,9 +357,12 @@ struct SliceBase {
354357
return 0.0 <= v && v <= kMax;
355358
}
356359

357-
// may throw if value is < 0
358-
uint64_t v = getUInt();
359-
return (v <= static_cast<uint64_t>((std::numeric_limits<T>::max)()));
360+
if (isInteger()) {
361+
// may throw if value is < 0
362+
uint64_t v = getUInt();
363+
return (v <= static_cast<uint64_t>((std::numeric_limits<T>::max)()));
364+
}
365+
return false;
360366
}
361367
} else {
362368
// floating point type

0 commit comments

Comments
 (0)