From 97c9dba402d6d4097cbdc4c44c00222c53122033 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 13 Feb 2022 12:12:42 +0100 Subject: Fixed bug in reading scrambles with unmatched parentheses --- src/alg.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/alg.c') diff --git a/src/alg.c b/src/alg.c index 27af676..4f5079a 100644 --- a/src/alg.c +++ b/src/alg.c @@ -268,27 +268,31 @@ move_string(Move m) Alg * new_alg(char *str) { - Alg *alg = malloc(sizeof(Alg)); + Alg *alg; int i; - bool niss = false, move_read; + bool niss, move_read; Move j, m; + alg = malloc(sizeof(Alg)); alg->move = malloc(30 * sizeof(Move)); alg->inv = malloc(30 * sizeof(bool)); alg->allocated = 30; alg->len = 0; + niss = false; for (i = 0; str[i]; i++) { if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') continue; if (str[i] == '(' && niss) { fprintf(stderr, "Error reading moves: nested ( )\n"); + alg->len = 0; return alg; } if (str[i] == ')' && !niss) { fprintf(stderr, "Error reading moves: unmatched )\n"); + alg->len = 0; return alg; } @@ -353,6 +357,11 @@ new_alg(char *str) } } + if (niss) { + fprintf(stderr, "Error reading moves: unmatched (\n"); + alg->len = 0; + } + return alg; } -- cgit v1.3