1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

fix segfaults when closing the current input port

* libguile/ports.c (scm_char_ready_p, scm_peek_char, scm_unread_char)
  (scm_unread_string): Always validate the port, even in the case that
  we get it the default current-input-port. Otherwise the following
  causes a segfault:

    (begin (close-port (current-input-port)) (peek-char))
This commit is contained in:
Andy Wingo 2010-10-10 12:13:04 +02:00
parent 1924145df5
commit b2456dd434

View file

@ -261,8 +261,9 @@ SCM_DEFINE (scm_char_ready_p, "char-ready?", 0, 1, 0,
if (SCM_UNBNDP (port))
port = scm_current_input_port ();
else
SCM_VALIDATE_OPINPORT (1, port);
/* It's possible to close the current input port, so validate even in
this case. */
SCM_VALIDATE_OPINPORT (1, port);
pt = SCM_PTAB_ENTRY (port);
@ -1656,8 +1657,7 @@ SCM_DEFINE (scm_peek_char, "peek-char", 0, 1, 0,
if (SCM_UNBNDP (port))
port = scm_current_input_port ();
else
SCM_VALIDATE_OPINPORT (1, port);
SCM_VALIDATE_OPINPORT (1, port);
column = SCM_COL (port);
line = SCM_LINUM (port);
@ -1695,8 +1695,7 @@ SCM_DEFINE (scm_unread_char, "unread-char", 1, 1, 0,
SCM_VALIDATE_CHAR (1, cobj);
if (SCM_UNBNDP (port))
port = scm_current_input_port ();
else
SCM_VALIDATE_OPINPORT (2, port);
SCM_VALIDATE_OPINPORT (2, port);
c = SCM_CHAR (cobj);
@ -1717,8 +1716,7 @@ SCM_DEFINE (scm_unread_string, "unread-string", 2, 0, 0,
SCM_VALIDATE_STRING (1, str);
if (SCM_UNBNDP (port))
port = scm_current_input_port ();
else
SCM_VALIDATE_OPINPORT (2, port);
SCM_VALIDATE_OPINPORT (2, port);
n = scm_i_string_length (str);