Fix #98480 math when reading shared memory
authorLeon Timmermans <fawaka@gmail.com>
Tue, 13 Sep 2011 18:13:22 +0000 (20:13 +0200)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 14 Sep 2011 19:50:00 +0000 (12:50 -0700)
shmread didn't unset SvIOK properly, causing a read into a SVIV to have
an incorrect numeric value. This patch fixes that and adds tests.

doio.c
t/io/shm.t

diff --git a/doio.c b/doio.c
index cb77cf6..1edf8d2 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -2278,7 +2278,8 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
        /* suppress warning when reading into undef var (tchrist 3/Mar/00) */
        if (! SvOK(mstr))
            sv_setpvs(mstr, "");
-       SvPV_force_nolen(mstr);
+       sv_upgrade(mstr, SVt_PV);
+       SvPOK_only(mstr);
        mbuf = SvGROW(mstr, (STRLEN)msize+1);
 
        Copy(shm + mpos, mbuf, msize, char);
index a450679..46bb2e1 100644 (file)
@@ -54,7 +54,7 @@ if (not defined $key) {
   }
 }
 else {
-       plan(tests => 11);
+       plan(tests => 13);
        pass('acquired shared mem');
 }
 
@@ -73,3 +73,9 @@ ok(shmread($key, $var, 1, 6), 'read(offs=1) returned ok');
 is($var, 'Shared', 'read(offs=1) correct');
 ok(shmwrite($key,"Memory", 0, 6), 'write(offs=0)');
 
+my $number = 1;
+my $int = 2;
+shmwrite $key, $int, 0, 1;
+shmread $key, $number, 0, 1;
+is("$number", $int, qq{"\$id" eq "$int"});
+cmp_ok($number + 0, '==', $int, "\$id + 0 == $int");