diff options
-rw-r--r-- | sb.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -55,11 +55,12 @@ void insstr(sb* buf, char* str){ buf->loc += rem; } -sbnode* freenodenext(sbnode* node){ +static sbnode* freenext(sbnode* node){ sbnode* out = node->next; free(node->str); free(node); - return out; + if (node != out) return out; + else return node; } char* decompose(sb* buf){ @@ -77,7 +78,7 @@ char* decompose(sb* buf){ // and its iterator char* pos = str; // for every node, - for (sbnode* cur = buf->head; cur != NULL; cur = freenodenext(cur)){ + for (sbnode* cur = buf->head; cur != NULL; cur = freenext(cur)){ size_t slen = strlen(cur->str); memcpy(pos, cur->str, slen); // copy pos += slen; |