commit 16e67d4ebb312a838ca6be4f9b3b43ec5ea212a4
Author: Enrico Forestieri <[email protected]>
Date:   Fri Jan 27 20:34:24 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 |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 1e36f5a..aba4ab7 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -988,8 +988,16 @@ 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 = def.at(pos + name().size());
+                               if (pos < 0 || (name().size() > 1 &&
+                                               ((c >= 'a' && c <= 'z') ||
+                                                (c >= 'A' && c <= 'Z')))) {
+                                       asArray(def, ar);
+                                       ar.validate(features);
+                               }
                        }
                }
        }
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to