]> git.lyx.org Git - features.git/commitdiff
Fix bug #12633
authorEnrico Forestieri <forenr@lyx.org>
Fri, 27 Jan 2023 19:34:24 +0000 (20:34 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 27 Jan 2023 19:34:24 +0000 (20:34 +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

index 1e36f5a53db1779e8b4458a4c280de55f762facd..aba4ab79a0d215b6c1bb23d2fb2e9681f123d002 100644 (file)
@@ -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);
+                               }
                        }
                }
        }