]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #12633
authorEnrico Forestieri <forenr@lyx.org>
Sat, 28 Jan 2023 08:03:49 +0000 (09:03 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 28 Jan 2023 08:03:49 +0000 (09:03 +0100)
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
status.23x

index 65f677e48cac4b13976c96ee20f39a849355b762..50cc3c3e71dbe7a64057ba31d2421234135465fd 100644 (file)
@@ -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);
index c6b4b7618bf6c9fb473449d700309475703b23d9..acf0fa9da73b21645a56364b8b1d233b2bd07493 100644 (file)
@@ -42,6 +42,7 @@ What's new
 
 * USER INTERFACE
 
+- Avoid crashing on a recursive macro definition (bug 12633).
 
 
 * INTERNALS