diff options
author | hunt <hunt> | 2007-09-12 19:10:36 +0000 |
---|---|---|
committer | hunt <hunt> | 2007-09-12 19:10:36 +0000 |
commit | e38723d2391f4e274b46317187179a18bfb5135f (patch) | |
tree | 554ddf235caca4327e5c71c4e565e1248daff9ad /parse.cxx | |
parent | 87ebf4cbc06b84d70548869290bf4dcc1964b5e0 (diff) | |
download | systemtap-steved-e38723d2391f4e274b46317187179a18bfb5135f.tar.gz systemtap-steved-e38723d2391f4e274b46317187179a18bfb5135f.tar.xz systemtap-steved-e38723d2391f4e274b46317187179a18bfb5135f.zip |
2007-09-12 Martin Hunt <hunt@redhat.com>
PR 5019
* elaborate.cxx (visit_hist_op): Remove log histogram param.
* translate.cxx (assert_hist_compatible): Ditto.
* staptree.cxx (hist_op::print): Ditto.
* session.h (statistic_decl): Ditto.
* parse.cxx (expect_number): Allow negative numbers.
Also validate that input is really numeric. This is used
by histograms to get the parameters.
(parse_hist_op_or_bare_name): Remove code to get parameter
for log histograms.
Diffstat (limited to 'parse.cxx')
-rw-r--r-- | parse.cxx | 52 |
1 files changed, 30 insertions, 22 deletions
@@ -451,13 +451,37 @@ parser::expect_kw (std::string const & expected) } const token* -parser::expect_number (int64_t & expected) +parser::expect_number (int64_t & value) { - std::string tmp; - token const * tt = expect_unknown (tok_number, tmp); - istringstream iss(tmp); - iss >> expected; - return tt; + bool neg = false; + const token *t = next(); + if (t->type == tok_operator && t->content == "-") + { + neg = true; + t = next (); + } + if (!(t && t->type == tok_number)) + throw parse_error ("expected number"); + + const char* startp = t->content.c_str (); + char* endp = (char*) startp; + + // NB: we allow controlled overflow from LLONG_MIN .. ULLONG_MAX + // Actually, this allows all the way from -ULLONG_MAX to ULLONG_MAX, + // since the lexer only gives us positive digit strings, but we'll + // limit it to LLONG_MIN when a '-' operator is fed into the literal. + errno = 0; + value = (int64_t) strtoull (startp, & endp, 0); + if (errno == ERANGE || errno == EINVAL || *endp != '\0' + || (neg && (unsigned long long) value > 9223372036854775808ULL) + || (unsigned long long) value > 18446744073709551615ULL + || value < -9223372036854775807LL-1) + throw parse_error ("number invalid or out of range"); + + if (neg) + value = -value; + + return t; } @@ -2171,22 +2195,6 @@ parser::parse_hist_op_or_bare_name (hist_op *&hop, string &name) hop->params.push_back (tnum); } } - else - { - assert(hop->htype == hist_log); - if (peek_op (",")) - { - expect_op (","); - expect_number (tnum); - hop->params.push_back (tnum); - } - else - { - // FIXME (magic value): Logarithmic histograms get 64 - // buckets by default. - hop->params.push_back (64); - } - } expect_op(")"); } return t; |