Skip to content

Commit a4bcee2

Browse files
committed
Preset parser: Throw exception instead of calling SIGABRT if expression can't be parsed.
1 parent bd6d980 commit a4bcee2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libprojectM/MilkdropPresetFactory/Parser.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <locale>
4343
#include <map>
4444
#include <sstream>
45+
#include <stdexcept>
4546
#include <stdio.h>
4647
#include <stdlib.h>
4748
#include <string>
@@ -936,7 +937,10 @@ Expr * Parser::_parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, Milkd
936937
return NULL;
937938
}
938939
}
939-
assert(param);
940+
if (param == NULL)
941+
{
942+
throw std::runtime_error("Preset parsing failed: custom parameter is NULL in line " + std::to_string(line_count));
943+
}
940944

941945
if (PARSE_DEBUG)
942946
{
@@ -1238,7 +1242,10 @@ Expr * Parser::parse_infix_op(std::istream & fs, token_t token, TreeExpr * tree
12381242
case tComma:
12391243
if (PARSE_DEBUG) printf("parse_infix_op: terminal found (LINE %d)\n", line_count);
12401244
gen_expr = tree_expr;
1241-
assert(gen_expr);
1245+
if (gen_expr == NULL)
1246+
{
1247+
throw std::runtime_error("Preset parse error: Unexpected terminal character in line " + std::to_string(line_count));
1248+
}
12421249
return gen_expr;
12431250
default:
12441251
if (PARSE_DEBUG) printf("parse_infix_op: operator or terminal expected, but not found (LINE %d)\n", line_count);

0 commit comments

Comments
 (0)