Sync with 2.12.5
[gitweb.git] / builtin / mailsplit.c
index 30681681c1389826513464385405dfe6ef8a2855..664400b8169b673f735e77f7dd86474f1665a3ae 100644 (file)
@@ -232,6 +232,16 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
 
        do {
                peek = fgetc(f);
+               if (peek == EOF) {
+                       if (f == stdin)
+                               /* empty stdin is OK */
+                               ret = skip;
+                       else {
+                               fclose(f);
+                               error(_("empty mbox: '%s'"), file);
+                       }
+                       goto out;
+               }
        } while (isspace(peek));
        ungetc(peek, f);