[LyX/2.3.x] Fix bug #12633

Enrico Forestieri forenr at lyx.org
Sat Jan 28 07:04:46 UTC 2023


commit 8bc83f123a60615d5bcdb8f15817ba0ca25f2ebf
Author: Enrico Forestieri <forenr at lyx.org>
Date:   Sat Jan 28 09:03:49 2023 +0100

    Fix bug #12633
    
    Avoid recursion when validating a macro that is defined recursively.
    This avoids a crash but the latex engine will choke on it, of course.
---
 src/mathed/InsetMathMacro.cpp |   13 +++++++++++--
 status.23x                    |    1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 65f677e..50cc3c3 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -917,8 +917,17 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const
 		MathData ar(const_cast<Buffer *>(&buffer()));
 		MacroData const * data = buffer().getMacro(name());
 		if (data) {
-			asArray(data->definition(), ar);
-			ar.validate(features);
+			// Avoid recursion on a recursive macro definition
+			docstring const & def = data->definition();
+			int pos = tokenPos(def, '\\', name());
+			char_type c = pos + name().size() < def.size()
+					? def.at(pos + name().size()) : 0;
+			if (pos < 0 || (name().size() > 1 &&
+					((c >= 'a' && c <= 'z') ||
+					 (c >= 'A' && c <= 'Z')))) {
+				asArray(def, ar);
+				ar.validate(features);
+			}
 		}
 	}
 	InsetMathNest::validate(features);
diff --git a/status.23x b/status.23x
index c6b4b76..acf0fa9 100644
--- a/status.23x
+++ b/status.23x
@@ -42,6 +42,7 @@ What's new
 
 * USER INTERFACE
 
+- Avoid crashing on a recursive macro definition (bug 12633).
 
 
 * INTERNALS


More information about the lyx-cvs mailing list