From 3e3179b4d4ee5002e41ebd27ab3504200a8d4260 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 11 May 2009 11:02:25 +0000 Subject: [PATCH] Hopefully complete fix to bug #5935 Make several Parser methods return copies of tokens, because the vector containing the token may get reallocated when it grows. Revert now useless changeset 29557. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29627 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/Parser.cpp | 12 ++++++++---- src/tex2lyx/Parser.h | 8 ++++---- src/tex2lyx/text.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index 5dce0ab792..8fbadfef24 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -166,28 +166,32 @@ void Parser::push_back(Token const & t) } -Token const & Parser::prev_token() const +// We return a copy here because the tokens_ vector may get reallocated +Token const Parser::prev_token() const { static const Token dummy; return pos_ > 1 ? tokens_[pos_ - 2] : dummy; } -Token const & Parser::curr_token() const +// We return a copy here because the tokens_ vector may get reallocated +Token const Parser::curr_token() const { static const Token dummy; return pos_ > 0 ? tokens_[pos_ - 1] : dummy; } -Token const & Parser::next_token() +// We return a copy here because the tokens_ vector may get reallocated +Token const Parser::next_token() { static const Token dummy; return good() ? tokens_[pos_] : dummy; } -Token const & Parser::get_token() +// We return a copy here because the tokens_ vector may get reallocated +Token const Parser::get_token() { static const Token dummy; //cerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n'; diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index d26c5127a4..c79296175e 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -180,13 +180,13 @@ public: /// void push_back(Token const & t); /// The previous token. - Token const & prev_token() const; + Token const prev_token() const; /// The current token. - Token const & curr_token() const; + Token const curr_token() const; /// The next token. - Token const & next_token(); + Token const next_token(); /// Make the next token current and return that. - Token const & get_token(); + Token const get_token(); /// \return whether the current token starts a new paragraph bool isParagraph(); /// skips spaces (and comments if \p skip_comments is true) diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index dc0063bc31..732fa97161 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1139,7 +1139,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, bool const use_natbib = used_packages.find("natbib") != used_packages.end(); bool const use_jurabib = used_packages.find("jurabib") != used_packages.end(); while (p.good()) { - Token const t = p.get_token(); + Token const & t = p.get_token(); #ifdef FILEDEBUG cerr << "t: " << t << " flags: " << flags << "\n";