fix dot crashing in multiple places

This commit is contained in:
2026-10-07 18:11:39 +03:00
parent 8bc359fed6
commit 0777faa11d
3 changed files with 17 additions and 4 deletions
+2 -1
View File
@@ -302,11 +302,12 @@ public:
// if value, left and right hands should be null // if value, left and right hands should be null
explicit TreeNode(void) explicit TreeNode(void)
: l(nullptr), r(nullptr), o()
{ {
} }
explicit TreeNode(const Token t) explicit TreeNode(const Token t)
: o(t) : l(nullptr), r(nullptr), o(t)
{ {
} }
+8 -2
View File
@@ -377,7 +377,10 @@ void print_token_vector(const std::vector<Expression::Token>& tv)
std::cout << "(" << *tv[i].to_str() << ") "; std::cout << "(" << *tv[i].to_str() << ") ";
} }
std::cout << "(" << *tv[i].to_str() << ")\n"; if (tv.size())
{
std::cout << "(" << *tv[i].to_str() << ")\n";
}
} }
void print_math_vector(const std::vector<Expression::Token>& tv) void print_math_vector(const std::vector<Expression::Token>& tv)
@@ -388,7 +391,10 @@ void print_math_vector(const std::vector<Expression::Token>& tv)
std::cout << *tv[i].to_math_str(); //<< " "; std::cout << *tv[i].to_math_str(); //<< " ";
} }
std::cout << *tv[i].to_math_str() << "\n"; if (tv.size())
{
std::cout << *tv[i].to_math_str() << "\n";
}
} }
} }
+7 -1
View File
@@ -35,6 +35,7 @@ int check_syntax(std::vector<Expression::Token>& tv)
int problem_cnt = 0; int problem_cnt = 0;
// check start and finish validity // check start and finish validity
if (tv.size())
{ {
int pc = problem_cnt; int pc = problem_cnt;
@@ -101,6 +102,7 @@ int check_syntax(std::vector<Expression::Token>& tv)
} }
// check token type sequence // check token type sequence
if (tv.size() > 1)
{ {
for (int i = 0, l = tv.size() - 1, pc; pc = problem_cnt, i < l; i++) for (int i = 0, l = tv.size() - 1, pc; pc = problem_cnt, i < l; i++)
{ {
@@ -812,7 +814,11 @@ Expression::TreeNode ov_to_tree(const std::vector<Expression::Token> tv, const s
{ {
Expression::TreeNode root; Expression::TreeNode root;
std::queue<std::pair<Expression::TreeNode *, int>> queued_ops; std::queue<std::pair<Expression::TreeNode *, int>> queued_ops;
queued_ops.emplace(&root, ov.size() - 1);
if (ov.size())
{
queued_ops.emplace(&root, ov.size() - 1);
}
while (queued_ops.size()) while (queued_ops.size())
{ {