From 95c44609a4d39e4fd70e74ba9d1d5c0bb8896188 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 28 Apr 2012 05:24:29 -0500 Subject: Made some of the value term parsing code more resilient --- src/token.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/token.cc') diff --git a/src/token.cc b/src/token.cc index e5d6b218..afe48b08 100644 --- a/src/token.cc +++ b/src/token.cc @@ -417,16 +417,18 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags) if (! temp.parse(in, parse_flags.plus_flags(PARSE_SOFT_FAIL))) { in.clear(); in.seekg(pos, std::ios::beg); - if (in.fail()) + if (in.fail() || ! in.good()) throw_(parse_error, _("Failed to reset input stream")); c = static_cast(in.peek()); - if (! std::isalpha(c) && c != '_') - expected('\0', c); + if (c != -1) { + if (! std::isalpha(c) && c != '_') + expected('\0', c); - parse_ident(in); + parse_ident(in); + } - if (value.as_string().length() == 0) { + if (! value.is_string() || value.as_string().empty()) { kind = ERROR; symbol[0] = c; symbol[1] = '\0'; -- cgit v1.2.3 From 96172669053bbba7263a370f109f70615049a0c6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 14 May 2012 21:37:36 -0600 Subject: Improved detection of iostream's eof() condition --- src/csv.cc | 2 +- src/token.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/token.cc') diff --git a/src/csv.cc b/src/csv.cc index 1e55129e..71b6516a 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -87,7 +87,7 @@ char * csv_reader::next_line(std::istream& in) while (in.good() && ! in.eof() && in.peek() == '#') in.getline(context.linebuf, parse_context_t::MAX_LINE); - if (! in.good() || in.eof()) + if (! in.good() || in.eof() || in.peek() == -1) return NULL; in.getline(context.linebuf, parse_context_t::MAX_LINE); diff --git a/src/token.cc b/src/token.cc index afe48b08..1392c29f 100644 --- a/src/token.cc +++ b/src/token.cc @@ -148,7 +148,7 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags) char c = peek_next_nonws(in); - if (in.eof()) { + if (in.eof() || c == -1) { kind = TOK_EOF; return; } @@ -426,6 +426,8 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags) expected('\0', c); parse_ident(in); + } else { + throw_(parse_error, _("Unexpected EOF")); } if (! value.is_string() || value.as_string().empty()) { -- cgit v1.2.3