* genio.c (scm_do_read_line): Don't just politely check that the
authorJim Blandy <jimb@red-bean.com>
Mon, 12 Oct 1998 20:09:34 +0000 (20:09 +0000)
committerJim Blandy <jimb@red-bean.com>
Mon, 12 Oct 1998 20:09:34 +0000 (20:09 +0000)
line was either non-empty or EOF.  Abort if it's empty and not
EOF.

libguile/genio.c

index 6072aa4..51e18ec 100644 (file)
@@ -183,11 +183,18 @@ scm_do_read_line (port, len)
   i = SCM_PTOBNUM (port);
   SCM_SYSCALL (s = (scm_ptobs[i].fgets) (port, len));
 
+  /* We should never get an empty string.  Every line has a newline at
+     the end, except for the last one.  If the last line has no
+     newline and is empty, then that's just an ordinary EOF, and we
+     should have s == NULL.  But this seems obscure to me, so we check
+     this here, to protect ourselves from odd port implementations.  */
+  if (s && *len <= 0)
+    abort ();
+
   /* If we're not at EOF, and there was a newline at the end of the
      string, increment the line counter.  */
-  if (s && *len > 0 && s[*len - 1] == '\n')
+  if (s && s[*len - 1] == '\n')
     SCM_INCLINE(port);
 
   return s;
 }
-