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 --- TODO.md | 3 +++ nissy | Bin 322488 -> 322488 bytes nissy-2.0.tar.gz | Bin 65160 -> 0 bytes src/alg.c | 13 +++++++++++-- src/commands.c | 13 +------------ 5 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 nissy-2.0.tar.gz diff --git a/TODO.md b/TODO.md index 40d8cc4..b321a92 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,9 @@ This is a list of things that I would like to add or change at some point. It's more of a personal reminder than anything else. ## For version 2.1 +### Bugs +* when reading scramble, unmatched ( does not produce any error, unmatched ) +produces TWO errors but it goes on anyway ### Scrambles * Better two-phase solver, make sure to not have cancelling moves (possibly use cleanup function) diff --git a/nissy b/nissy index 06e7708..c70e746 100755 Binary files a/nissy and b/nissy differ diff --git a/nissy-2.0.tar.gz b/nissy-2.0.tar.gz deleted file mode 100644 index 29172d0..0000000 Binary files a/nissy-2.0.tar.gz and /dev/null differ 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; } diff --git a/src/commands.c b/src/commands.c index 740736c..d9d6b50 100644 --- a/src/commands.c +++ b/src/commands.c @@ -519,25 +519,14 @@ read_scramble(int c, char **v, CommandArgs *args) int i, k, n; unsigned int j; char *algstr; - Alg *aux; if (c < 1) { fprintf(stderr, "Error: no scramble given?\n"); return false; } - n = 0; - for(i = 0; i < c; i++) { - aux = new_alg(v[i]); - if (aux->len == 0) { - fprintf(stderr, "Error: %s or its argument" - "unrecognized\n", v[i]); - free(aux); - return false; - } - free(aux); + for(n = 0, i = 0; i < c; i++) n += strlen(v[i]); - } algstr = malloc((n + 1) * sizeof(char)); k = 0; -- cgit v1.3