From 5f3cd55f1dcd85626277968891e5e12bc07287fc Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 16 Feb 2013 14:16:42 +0100 Subject: [PATCH] Fix dangerous parser use Jean-Marc discovered a possible data loss caused by Parser::getChar(). This is now fixed, and Parser::getChar() is removed, since it is no longer needed and easy to use it in the wrong way. --- src/tex2lyx/Parser.cpp | 8 -------- src/tex2lyx/Parser.h | 5 ----- src/tex2lyx/text.cpp | 6 +++--- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index f5f5f46513..547f424b9d 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -413,14 +413,6 @@ bool Parser::good() } -char Parser::getChar() -{ - if (!good()) - error("The input stream is not well..."); - return get_token().character(); -} - - bool Parser::hasOpt() { // An optional argument can occur in any of the following forms: diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index 5f8b1fa98c..3c55a7ebb0 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -282,11 +282,6 @@ public: std::string verbatim_item(); /// std::string verbatimOption(); - /*! - * Returns the character of the current token and increments - * the token position. - */ - char getChar(); /// void error(std::string const & msg); /// The previous token. diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 07cb0775bd..2bf2c5aef4 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2105,10 +2105,10 @@ void parse_macro(Parser & p, ostream & os, Context & context) // followed by number? if (p.next_token().cat() == catOther) { - char c = p.getChar(); - paramtext += c; + string s = p.get_token().asInput(); + paramtext += s; // number = current arity + 1? - if (c == arity + '0' + 1) + if (s.size() == 1 && s[0] == arity + '0' + 1) ++arity; else simple = false;