This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix core dump on IO::Seekable::setpos($fh, undef)
[perl5.git] / ext / IO / IO.xs
index 8611b2d..2eb16f4 100644 (file)
@@ -106,11 +106,12 @@ fsetpos(handle, pos)
        InputStream     handle
        SV *            pos
     CODE:
-       if (handle)
+       char *p;
+       if (handle && (p = SvPVx(pos, na)) && na == sizeof(Fpos_t))
 #ifdef PerlIO
-           RETVAL = PerlIO_setpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = PerlIO_setpos(handle, (Fpos_t*)p);
 #else
-           RETVAL = fsetpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = fsetpos(handle, (Fpos_t*)p);
 #endif
        else {
            RETVAL = -1;
@@ -268,8 +269,8 @@ setvbuf(handle, buf, type, size)
        int             type
        int             size
     CODE:
-#ifdef PERLIO_IS_STDIO
-#ifdef _IOFBF   /* Should be HAS_SETVBUF once Configure tests for that */
+/* Should check HAS_SETVBUF once Configure tests for that */
+#if defined(PERLIO_IS_STDIO) && defined(_IOFBF)
        if (handle)
            RETVAL = setvbuf(handle, buf, type, size);
        else {
@@ -277,10 +278,7 @@ setvbuf(handle, buf, type, size)
            errno = EINVAL;
        }
 #else
-           RETVAL = (SysRet) not_here("IO::Handle::setvbuf");
-#endif /* _IOFBF */
-#else
-           not_here("IO::Handle::setvbuf");
+       RETVAL = (SysRet) not_here("IO::Handle::setvbuf");
 #endif
     OUTPUT:
        RETVAL