From 112a83c346a537f1a5eac6fc17ee2ce3143d625b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 18 Jun 2020 16:40:00 +0300 Subject: Fix lexer to fail on invalid UTF-8 sequences --- libbuild2/lexer.hxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libbuild2/lexer.hxx') diff --git a/libbuild2/lexer.hxx b/libbuild2/lexer.hxx index 6c2b90b..cc42219 100644 --- a/libbuild2/lexer.hxx +++ b/libbuild2/lexer.hxx @@ -187,6 +187,23 @@ namespace build2 pair, bool> peek_chars (); + // As base::get() but in case of an invalid character issue diagnostics + // and throw failed. + // + xchar + get (); + + // Get previously peeked character (faster). + // + void + get (const xchar&); + + // As base::peek() but in case of an invalid character issue diagnostics + // and throw failed. + // + xchar + peek (); + protected: struct state { @@ -243,6 +260,9 @@ namespace build2 protected: fail_mark fail; + [[noreturn]] void + fail_char (const xchar&); + // Lexer state. // protected: @@ -266,6 +286,13 @@ namespace build2 std::stack state_; bool sep_; // True if we skipped spaces in peek(). + + private: + using base = char_scanner; + + // Buffer for a get()/peek() potential error. + // + string ebuf_; }; } @@ -284,4 +311,6 @@ namespace butl // ADL } } +#include + #endif // LIBBUILD2_LEXER_HXX -- cgit v1.1