]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Handle edge cases at end-of-file properly.
authorBen Schmidt <none@none>
Mon, 23 Jan 2012 07:30:06 +0000 (18:30 +1100)
committerBen Schmidt <none@none>
Mon, 23 Jan 2012 07:30:06 +0000 (18:30 +1100)
src/prepstdreply.c

index cc07aa7fb763670ff230bfc13070698e91d8df72..28e68f8df33124302aded56d81be52defbe51d8a 100644 (file)
@@ -959,7 +959,7 @@ char *get_processed_text_line(text *txt, int headers,
                const char *listaddr, const char *listdelim,
                const char *listdir)
 {
-       char *line = NULL;
+       char *line;
        const char *item;
        char *pos;
        char *tmp, *spc;
@@ -971,6 +971,7 @@ char *get_processed_text_line(text *txt, int headers,
        int swallow;
 
        for (;;) {
+               line = NULL;
                while (txt->src != NULL) {
                        if (txt->src->upcoming != NULL) {
                                if (txt->src->prefix != NULL) {
@@ -1002,7 +1003,11 @@ char *get_processed_text_line(text *txt, int headers,
                        if (txt->src->upcoming != NULL) continue;
                        close_source(txt);
                }
-               if (line == NULL) return NULL;
+               if (line == NULL) {
+                       if (peeking) return mystrdup("");
+                       if (prev != NULL) return prev;
+                       return NULL;
+               }
 
                tmp = unistr_escaped_to_utf8(line);
                myfree(line);