commit ebb9d7b058604f3925c4b07e4dac533273f9b344 Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Thu Jul 13 19:03:06 2017 +0200
Avoid multiple execution of AddToPreamble and friends When trying to read a textclass, read(Lexer, Readtype) parses and executes the first token and only then verifies that its effect was to set format properly. Otherwise it exits. This is wrong, because if the first tag is "AddToPreamble", then it will have modified the preamble by the time we notice it was not "Format" and therefore exit. The new code starts by requiring a correct "Format" tag. Fixes bug #10725. --- src/TextClass.cpp | 18 ++++++++---------- 1 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 6943562..0a903cb 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -408,11 +408,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) if (!lexrc.isOK()) return ERROR; - // Format of files before the 'Format' tag was introduced - int format = 1; - bool error = false; + // The first usable line should be + // Format LAYOUT_FORMAT + if (lexrc.lex() != TC_FORMAT || !lexrc.next() + || lexrc.getInteger() != LAYOUT_FORMAT) + return FORMAT_MISMATCH; // parsing + bool error = false; while (lexrc.isOK() && !error) { int le = lexrc.lex(); @@ -437,8 +440,8 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) switch (static_cast<TextClassTags>(le)) { case TC_FORMAT: - if (lexrc.next()) - format = lexrc.getInteger(); + lexrc.next(); + lexrc.printError("Duplicate Format directive"); break; case TC_OUTPUTFORMAT: @@ -853,11 +856,6 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt) error = !readOutlinerName(lexrc); break; } // end of switch - - // Note that this is triggered the first time through the loop unless - // we hit a format tag. - if (format != LAYOUT_FORMAT) - return FORMAT_MISMATCH; } // at present, we abort if we encounter an error,