diff --git a/elements/test/confparsetest.cc b/elements/test/confparsetest.cc index 04d8476833..3566eada68 100644 --- a/elements/test/confparsetest.cc +++ b/elements/test/confparsetest.cc @@ -132,6 +132,7 @@ ConfParseTest::initialize(ErrorHandler *errh) CHECK(IntArg().parse("-0", i32) == true && i32 == 0); CHECK(IntArg().parse("-5", i32) == true && i32 == -5); CHECK(u32 == 97); + CHECK_ERR(IntArg().parse("aoeu", u32, args) == false && u32 == 97, "invalid number"); CHECK(IntArg().parse("0", u32) == true && u32 == 0); CHECK(IntArg().parse("-0", u32) == false); CHECK(IntArg().parse("4294967294", u32) == true && u32 == 4294967294U); @@ -174,6 +175,7 @@ ConfParseTest::initialize(ErrorHandler *errh) CHECK_ERR(BoundedIntArg(0U, 100U).parse("-1", i32, args) == false && i32 == 10, "out of range, bound 0"); CHECK_ERR(BoundedIntArg(0U, 100U).parse("-1", i32, args) == false && i32 == 10, "out of range, bound 0"); CHECK_ERR(BoundedIntArg(0U, ~0U).parse("-1", i32, args) == false && i32 == 10, "out of range, bound 0"); + CHECK_ERR(BoundedIntArg(-1, 9).parse("aoeu", i32, args) == false && i32 == 10, "invalid number"); bool b; (void) b; CHECK(FixedPointArg(1).parse("0.5", i32) == true && i32 == 1); diff --git a/include/click/args.hh b/include/click/args.hh index 9e33ee8a70..197e464ffb 100644 --- a/include/click/args.hh +++ b/include/click/args.hh @@ -1051,15 +1051,16 @@ class IntArg : public NumArg { public: template bool parse_saturating(const String &str, V &result, const ArgContext &args = blank_args) { - (void) args; constexpr bool is_signed = integer_traits::is_signed; constexpr int nlimb = int((sizeof(V) + sizeof(limb_type) - 1) / sizeof(limb_type)); limb_type x[nlimb]; if (parse(str.begin(), str.end(), is_signed, int(sizeof(V)), x, nlimb) != str.end()) status = status_inval; - if (status && status != status_range) + if (status && status != status_range) { + args.error("invalid number"); return false; + } typedef typename make_unsigned::type unsigned_v_type; extract_integer(x, reinterpret_cast(result)); return true;