aboutsummaryrefslogtreecommitdiff
path: root/src/alg.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-02-13 12:12:42 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2022-02-13 12:12:42 +0100
commit97c9dba402d6d4097cbdc4c44c00222c53122033 (patch)
treef604aa049737b5e486924c88f86d91106428ec24 /src/alg.c
parentac458f4de9a1d5fa203bed7b57de05ea65451788 (diff)
downloadnissy-97c9dba402d6d4097cbdc4c44c00222c53122033.tar.gz
nissy-97c9dba402d6d4097cbdc4c44c00222c53122033.zip
Fixed bug in reading scrambles with unmatched parentheses
Diffstat (limited to 'src/alg.c')
-rw-r--r--src/alg.c13
1 files changed, 11 insertions, 2 deletions
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)
268Alg * 268Alg *
269new_alg(char *str) 269new_alg(char *str)
270{ 270{
271 Alg *alg = malloc(sizeof(Alg)); 271 Alg *alg;
272 int i; 272 int i;
273 bool niss = false, move_read; 273 bool niss, move_read;
274 Move j, m; 274 Move j, m;
275 275
276 alg = malloc(sizeof(Alg));
276 alg->move = malloc(30 * sizeof(Move)); 277 alg->move = malloc(30 * sizeof(Move));
277 alg->inv = malloc(30 * sizeof(bool)); 278 alg->inv = malloc(30 * sizeof(bool));
278 alg->allocated = 30; 279 alg->allocated = 30;
279 alg->len = 0; 280 alg->len = 0;
280 281
282 niss = false;
281 for (i = 0; str[i]; i++) { 283 for (i = 0; str[i]; i++) {
282 if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') 284 if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n')
283 continue; 285 continue;
284 286
285 if (str[i] == '(' && niss) { 287 if (str[i] == '(' && niss) {
286 fprintf(stderr, "Error reading moves: nested ( )\n"); 288 fprintf(stderr, "Error reading moves: nested ( )\n");
289 alg->len = 0;
287 return alg; 290 return alg;
288 } 291 }
289 292
290 if (str[i] == ')' && !niss) { 293 if (str[i] == ')' && !niss) {
291 fprintf(stderr, "Error reading moves: unmatched )\n"); 294 fprintf(stderr, "Error reading moves: unmatched )\n");
295 alg->len = 0;
292 return alg; 296 return alg;
293 } 297 }
294 298
@@ -353,6 +357,11 @@ new_alg(char *str)
353 } 357 }
354 } 358 }
355 359
360 if (niss) {
361 fprintf(stderr, "Error reading moves: unmatched (\n");
362 alg->len = 0;
363 }
364
356 return alg; 365 return alg;
357} 366}
358 367

Generated with cgit - Back to sebastiano.tronto.net