浏览代码

HackStudio: Fixes CppLexer crashing on a comment block that does
not end.

CppLexer expected that `/*` always has `*/` at the end. This PR
fixes the issue and assumes the rest of file is a comment.

Sasan Hezarkhani 5 年之前
父节点
当前提交
30db7813de
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 11 3
      DevTools/HackStudio/CppLexer.cpp

+ 11 - 3
DevTools/HackStudio/CppLexer.cpp

@@ -278,13 +278,21 @@ Vector<CppToken> CppLexer::lex()
             begin_token();
             begin_token();
             consume();
             consume();
             consume();
             consume();
+            bool comment_block_ends = false;
             while (peek()) {
             while (peek()) {
-                if (peek() == '*' && peek(1) == '/')
+                if (peek() == '*' && peek(1) == '/') {
+                    comment_block_ends = true;
                     break;
                     break;
+                }
+
                 consume();
                 consume();
             }
             }
-            consume();
-            consume();
+
+            if (comment_block_ends) {
+                consume();
+                consume();
+            }
+
             commit_token(CppToken::Type::Comment);
             commit_token(CppToken::Type::Comment);
             continue;
             continue;
         }
         }