]> git.lyx.org Git - lyx.git/commitdiff
Fix issue with regular expressions
authorEnrico Forestieri <forenr@lyx.org>
Sun, 15 Oct 2017 13:29:33 +0000 (15:29 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 15 Oct 2017 13:42:39 +0000 (15:42 +0200)
At least with gcc 6.4, if the first parameter passed to
regex_match() is afterward changed, the second one gets
corrupted. This is avoided by using a temporary string.

(cherry picked from commit c16ccdb5fd25a14c096ef9dfa68975c77377bf41)

src/BiblioInfo.cpp

index 87245d3824f1c8c74f69e61798897dd195c8ed30..bb7c64cda2927fd2a3b72910746bffc02e055ada 100644 (file)
@@ -236,6 +236,8 @@ docstring constructName(docstring const & name, string const scheme)
        static regex const reg2("(.*)(\\{%suffix%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
        static regex const reg3("(.*)(\\{%prefix%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
        smatch sub;
+       // Changing the first parameter of regex_match() may corrupt the
+       // second one. In this case we use the temporary string tmp.
        if (regex_match(scheme, sub, reg1)) {
                res = sub.str(1);
                if (!prename.empty())
@@ -243,16 +245,16 @@ docstring constructName(docstring const & name, string const scheme)
                res += sub.str(5);
        }
        if (regex_match(res, sub, reg2)) {
-               res = sub.str(1);
+               string tmp = sub.str(1);
                if (!suffix.empty())
-                       res += sub.str(3);
-               res += sub.str(5);
+                       tmp += sub.str(3);
+               res = tmp + sub.str(5);
        }
        if (regex_match(res, sub, reg3)) {
-               res = sub.str(1);
+               string tmp = sub.str(1);
                if (!prefix.empty())
-                       res += sub.str(3);
-               res += sub.str(5);
+                       tmp += sub.str(3);
+               res = tmp + sub.str(5);
        }
        docstring result = from_ascii(res);
        result = subst(result, from_ascii("%prename%"), prename);