mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix crash due to recursive function call when a counter references itself.
e.g.: Counter Name Version LabelString "\theVersion.0" End git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23166 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
21a3cd14d2
commit
52ccb98354
@ -339,10 +339,23 @@ docstring Counters::labelItem(docstring const & ctr,
|
||||
|
||||
|
||||
docstring Counters::theCounter(docstring const & counter)
|
||||
{
|
||||
std::set<docstring> callers;
|
||||
return theCounter(counter, callers);
|
||||
}
|
||||
|
||||
docstring Counters::theCounter(docstring const & counter,
|
||||
std::set<docstring> & callers)
|
||||
{
|
||||
if (!hasCounter(counter))
|
||||
return from_ascii("??");
|
||||
|
||||
docstring label;
|
||||
|
||||
if (callers.find(counter) == callers.end()) {
|
||||
|
||||
pair<std::set<docstring>::iterator, bool> result = callers.insert(counter);
|
||||
|
||||
Counter const & c = counterList[counter];
|
||||
docstring ls = appendix() ? c.labelStringAppendix() : c.labelString();
|
||||
|
||||
@ -351,11 +364,23 @@ docstring Counters::theCounter(docstring const & counter)
|
||||
ls = from_ascii("\\the") + c.master() + from_ascii(".");
|
||||
ls += from_ascii("\\arabic{") + counter + "}";
|
||||
}
|
||||
return counterLabel(ls);
|
||||
|
||||
label = counterLabel(ls, &callers);
|
||||
|
||||
callers.erase(result.first);
|
||||
} else {
|
||||
// recursion detected
|
||||
lyxerr << "Warning: Recursion in label for counter `"
|
||||
<< counter << "' detected"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
docstring Counters::counterLabel(docstring const & format)
|
||||
docstring Counters::counterLabel(docstring const & format,
|
||||
std::set<docstring> * callers)
|
||||
{
|
||||
docstring label = format;
|
||||
|
||||
@ -373,7 +398,8 @@ docstring Counters::counterLabel(docstring const & format)
|
||||
&& lowercase(label[k]) <= 'z')
|
||||
++k;
|
||||
docstring counter = label.substr(j, k - j);
|
||||
docstring repl = theCounter(counter);
|
||||
docstring repl = callers? theCounter(counter, *callers):
|
||||
theCounter(counter);
|
||||
label.replace(i, k - j + 4, repl);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -105,7 +106,8 @@ public:
|
||||
docstring theCounter(docstring const & c);
|
||||
/// Replace om format all the LaTeX-like macros that depend on
|
||||
/// counters.
|
||||
docstring counterLabel(docstring const & format);
|
||||
docstring counterLabel(docstring const & format,
|
||||
std::set<docstring> * callers = 0);
|
||||
/// Are we in apendix?
|
||||
bool appendix() const { return appendix_; };
|
||||
/// Set the state variable indicating whether we are in appendix.
|
||||
@ -115,6 +117,10 @@ public:
|
||||
/// Sets the current enclosing float.
|
||||
void current_float(std::string const & f) { current_float_ = f; }
|
||||
private:
|
||||
/// returns the expanded string representation of the counter
|
||||
/// with recursion protection through callers.
|
||||
docstring theCounter(docstring const & c,
|
||||
std::set<docstring> & callers);
|
||||
/// Returns the value of the counter according to the
|
||||
/// numbering scheme numbertype.
|
||||
/* Available numbering schemes are arabic (1, 2,...), roman
|
||||
|
Loading…
Reference in New Issue
Block a user