diff options
author | Daniel Cerqueira <dan.git@lispclub.com> | 2025-05-30 16:03:00 +0100 |
---|---|---|
committer | Daniel Cerqueira <dan.git@lispclub.com> | 2025-05-30 16:03:00 +0100 |
commit | 3915751b78122737ee3afa56b39e50cc237de6d3 (patch) | |
tree | 940cba8fc00f62f040f2bfe28a178aefa84d79f2 | |
parent | 07796eafad7f05fc1a842299849be27333bb03e5 (diff) |
fix bug in primitiveJoin()
-rw-r--r-- | liblali.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1040,27 +1040,30 @@ Object *primitiveJoin(Object **args, GC_PARAM) { else if ((*args)->car->type != TYPE_CONS) exceptionWithObject((*args)->car, "is not a list"); - unsigned long i = 1; Object *tmpCons = (*args)->car; + unsigned long i = strlen(tmpCons->car->string); for (; tmpCons->cdr != nil; tmpCons = tmpCons->cdr) - i += strlen(tmpCons->car->string); + i += strlen(tmpCons->cdr->car->string); - char symbolResult[i]; + char symbolResult[i+1]; tmpCons = (*args)->car; unsigned long wordLength = strlen(tmpCons->car->string); + unsigned long j = 0; // first list element - for (int j = 0; j < wordLength; j++) + for (; j < wordLength; j++) symbolResult[j] = tmpCons->car->string[j]; // rest of list elements - for (i = wordLength; tmpCons->cdr != nil; tmpCons = tmpCons->cdr) { - wordLength = strlen(tmpCons->cdr->car->string); - for (int j = 0; j < wordLength; j++) - symbolResult[i+j] = tmpCons->cdr->car->string[j]; - i += wordLength; + if (tmpCons->cdr->car != nil) { + for (i = wordLength; tmpCons->cdr != nil; tmpCons = tmpCons->cdr) { + wordLength = strlen(tmpCons->cdr->car->string); + for (j = 0; j < wordLength; j++) + symbolResult[i+j] = tmpCons->cdr->car->string[j]; + i += j; + } } - + symbolResult[i] = '\0'; return newSymbol(symbolResult, GC_ROOTS); } |