diff options
author | Chip Salzenberg <chip@perl.com> | 1997-02-05 04:37:26 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-05-16 10:15:00 +1200 |
commit | fefb19804f3b755117d0936d5a943a08ec9f6cab (patch) | |
tree | 13448b08aadfa4f62da610193e2abd418593ec9e | |
parent | 1f4739df3b104a71e91e8f6e96c33e6309e06d36 (diff) | |
download | perl-fefb19804f3b755117d0936d5a943a08ec9f6cab.tar.gz |
Fix core dump on IO::Seekable::setpos($fh, undef)
-rw-r--r-- | ext/IO/IO.xs | 7 | ||||
-rwxr-xr-x | t/lib/io_xs.t | 16 |
2 files changed, 18 insertions, 5 deletions
diff --git a/ext/IO/IO.xs b/ext/IO/IO.xs index 5efbf24815..2eb16f40ec 100644 --- a/ext/IO/IO.xs +++ b/ext/IO/IO.xs @@ -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; diff --git a/t/lib/io_xs.t b/t/lib/io_xs.t index 3426ebe896..1a6fd381a3 100755 --- a/t/lib/io_xs.t +++ b/t/lib/io_xs.t @@ -21,10 +21,22 @@ BEGIN { 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->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"; |