aboutsummaryrefslogtreecommitdiff
path: root/badroff.c
diff options
context:
space:
mode:
Diffstat (limited to 'badroff.c')
-rw-r--r--badroff.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/badroff.c b/badroff.c
index 7134261..7bdb3e7 100644
--- a/badroff.c
+++ b/badroff.c
@@ -145,21 +145,21 @@ llnode* accumlines(size_t* ct){ // returns tail of linked list
(*ct) = 0;
while (!endgroup){
char* ln = line();
+ if (!ln[0]) { // ln == ""
+ free(ln);
+ break;
+ }
size_t len = strlen(ln);
char* next;
while ( (next = breakstr(ln, &len))){
- printf("line %s\n",ln);
tail->next = appendll(tail, ln);
tail = tail->next;
(*ct)++;
- printf("added\n");
ln = next;
};
- printf("loop\n");
}
tail->next = head->next; // loop linked list
free(head);
- printf("here\n");
endgroup = false; // prevents false positive on next run
return tail;
}
@@ -332,7 +332,9 @@ char* line(void){
size_t sz;
if ( (sz = fillbuf(2)) == 0)
return "";
- char* twobytes = peekstrbuf(inbuf, 0, 2); // .., .\n, or ^.?
+ char twobytes[3];
+ char* peek = peekstrbuf(inbuf, 0, 2); // .., .\n, or ^.?
+ memcpy(twobytes, peek, 3); free(peek);
if (sz == 1 || twobytes[1] == '\n') return norm();
if (twobytes[0] == '.') popchrbuf(inbuf);
char* out;
@@ -343,7 +345,6 @@ char* line(void){
} else {
out = norm();
}
- free(twobytes);
nbspsub(out);
return out;
}