Fix bug #9112: There is a test here that seems intended to catch the

case where there are unbalanced braces, but it comes too late. In that
case, we try to check cmd[docstring::npos] and crash.
This commit is contained in:
Richard Heck 2014-05-08 18:19:55 -04:00
parent 769b585176
commit 6b0a8fbc96

View File

@ -537,8 +537,11 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
if (j + 1 < cmdend && cmd[j + 1] == '{') { if (j + 1 < cmdend && cmd[j + 1] == '{') {
size_t k = j + 1; size_t k = j + 1;
int count = 1; int count = 1;
while (k < cmdend && count && k != docstring::npos) { while (k < cmdend && count) {
k = cmd.find_first_of(from_ascii("{}"), k + 1); k = cmd.find_first_of(from_ascii("{}"), k + 1);
// braces may not be balanced
if (k == docstring::npos)
break;
if (cmd[k] == '{') if (cmd[k] == '{')
++count; ++count;
else else
@ -603,8 +606,11 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
k < cmdend && cmd[k] == '{') { k < cmdend && cmd[k] == '{') {
size_t l = k; size_t l = k;
int count = 1; int count = 1;
while (l < cmdend && count && l != docstring::npos) { while (l < cmdend && count) {
l = cmd.find_first_of(from_ascii("{}"), l + 1); l = cmd.find_first_of(from_ascii("{}"), l + 1);
// braces may not be balanced
if (l == docstring::npos)
break;
if (cmd[l] == '{') if (cmd[l] == '{')
++count; ++count;
else else