changeset 836:5ab7b62e8223

Handle edge cases at end-of-file properly.
author Ben Schmidt
date Mon, 23 Jan 2012 18:30:06 +1100
parents ac0272a516f7
children f51138584096
files src/prepstdreply.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/prepstdreply.c	Mon Jan 23 18:03:37 2012 +1100
+++ b/src/prepstdreply.c	Mon Jan 23 18:30:06 2012 +1100
@@ -959,7 +959,7 @@
 		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 @@
 	int swallow;
 
 	for (;;) {
+		line = NULL;
 		while (txt->src != NULL) {
 			if (txt->src->upcoming != NULL) {
 				if (txt->src->prefix != NULL) {
@@ -1002,7 +1003,11 @@
 			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);