[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-cvs
Subject: [LyX/master] Make LFUN_REPEAT more robust by limiting to 10000 iterations
From: Jean-Marc Lasgouttes <lasgouttes () lyx ! org>
Date: 2017-03-28 9:30:56
Message-ID: 20170328093056.ACB202800D3 () lyx ! lyx ! org
[Download RAW message or body]
commit 4488c45d090d84107cc6684f26e0bba1db271818
Author: Jean-Marc Lasgouttes <lasgouttes@lyx.org>
Date: Tue Mar 28 11:30:18 2017 +0200
Make LFUN_REPEAT more robust by limiting to 10000 iterations
---
src/LyXAction.cpp | 1 +
src/frontends/qt4/GuiApplication.cpp | 11 +++++++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 3cccc37..bb3bf3e 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3262,6 +3262,7 @@ void LyXAction::init()
/*!
* \var lyx::FuncCode lyx::LFUN_REPEAT
* \li Action: Repeat the given command.
+ * \li Notion: fails when the repeat count is greater than 10000.
* \li Syntax: repeat <COUNT> <LFUN-COMMAND>
* \li Origin: Andre, 27 Oct 2003
* \endvar
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index c27f4c8..3a0c601 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -1858,8 +1858,15 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
string countstr;
string rest = split(argument, countstr, ' ');
int const count = convert<int>(countstr);
- for (int i = 0; i < count; ++i)
- dispatch(lyxaction.lookupFunc(rest));
+ // an arbitrary number to limit number of iterations
+ int const max_iter = 10000;
+ if (count > max_iter) {
+ dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter));
+ dr.setError(true);
+ } else {
+ for (int i = 0; i < count; ++i)
+ dispatch(lyxaction.lookupFunc(rest));
+ }
break;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic