diff options
author | Chaosus <chaosus89@gmail.com> | 2024-08-10 11:07:53 +0300 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-16 16:39:51 +0200 |
commit | 3dc376ec0be1ba11ffdffbc3ca4f278b1a38cf9d (patch) | |
tree | a7865642cda4a89a2f0be00617838f34731652e1 /servers | |
parent | a7d79f9e6cd78de91deb2d3fa1257ebf1ab116b2 (diff) | |
download | redot-engine-3dc376ec0be1ba11ffdffbc3ca4f278b1a38cf9d.tar.gz |
Fix shader crash when the comma used in `for` loop as a trailing
(cherry picked from commit d74749fd60c81fd682187ca5eaf08819e55d76d9)
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/shader_language.cpp | 17 | ||||
-rw-r--r-- | servers/rendering/shader_language.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 431dca0ad4..9c4e3fb249 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -898,6 +898,13 @@ bool ShaderLanguage::_lookup_next(Token &r_tk) { return false; } +ShaderLanguage::Token ShaderLanguage::_peek() { + TkPos pre_pos = _get_tkpos(); + Token tk = _get_token(); + _set_tkpos(pre_pos); + return tk; +} + String ShaderLanguage::token_debug(const String &p_code) { clear(); @@ -8080,6 +8087,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun _set_error(RTR("The middle expression is expected to be a boolean operator.")); return ERR_PARSE_ERROR; } + tk = _peek(); + if (tk.type == TK_SEMICOLON) { + _set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk))); + return ERR_PARSE_ERROR; + } continue; } if (tk.type != TK_SEMICOLON) { @@ -8088,6 +8100,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } } else if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_EXPRESSION) { if (tk.type == TK_COMMA) { + tk = _peek(); + if (tk.type == TK_PARENTHESIS_CLOSE) { + _set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk))); + return ERR_PARSE_ERROR; + } continue; } if (tk.type != TK_PARENTHESIS_CLOSE) { diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 4a67c8f2d2..ad3b78546d 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -1037,6 +1037,7 @@ private: Token _make_token(TokenType p_type, const StringName &p_text = StringName()); Token _get_token(); bool _lookup_next(Token &r_tk); + Token _peek(); ShaderNode *shader = nullptr; |