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)
authorChip Salzenberg <chip@perl.com>
Tue, 4 Feb 1997 16:37:26 +0000 (04:37 +1200)
committerChip Salzenberg <chip@atlantic.net>
Thu, 15 May 1997 22:15:00 +0000 (10:15 +1200)
ext/IO/IO.xs
t/lib/io_xs.t

index 5efbf24..2eb16f4 100644 (file)
@@ -106,11 +106,12 @@ fsetpos(handle, pos)
        InputStream     handle
        SV *            pos
     CODE:
        InputStream     handle
        SV *            pos
     CODE:
-       if (handle)
+       char *p;
+       if (handle && (p = SvPVx(pos, na)) && na == sizeof(Fpos_t))
 #ifdef PerlIO
 #ifdef PerlIO
-           RETVAL = PerlIO_setpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = PerlIO_setpos(handle, (Fpos_t*)p);
 #else
 #else
-           RETVAL = fsetpos(handle, (Fpos_t*)SvPVX(pos));
+           RETVAL = fsetpos(handle, (Fpos_t*)p);
 #endif
        else {
            RETVAL = -1;
 #endif
        else {
            RETVAL = -1;
index 3426ebe..1a6fd38 100755 (executable)
@@ -21,10 +21,22 @@ BEGIN {
 use IO::File;
 use IO::Seekable;
 
 use IO::File;
 use IO::Seekable;
 
-print "1..2\n";
-use IO::File;
+print "1..4\n";
+
 $x = new_tmpfile IO::File or print "not ";
 print "ok 1\n";
 print $x "ok 2\n";
 $x->seek(0,SEEK_SET);
 print <$x>;
 $x = new_tmpfile IO::File or print "not ";
 print "ok 1\n";
 print $x "ok 2\n";
 $x->seek(0,SEEK_SET);
 print <$x>;
+
+$x->seek(0,SEEK_SET);
+print $x "not ok 3\n";
+$p = $x->getpos;
+print $x "ok 3\n";
+$x->flush;
+$x->setpos($p);
+print scalar <$x>;
+
+$! = 0;
+$x->setpos(undef);
+print $! ? "ok 4 # $!\n" : "not ok 4\n";