aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sb.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/sb.c b/sb.c
index 06ee8d9..e1cbd63 100644
--- a/sb.c
+++ b/sb.c
@@ -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;