From: Leon Timmermans Date: Tue, 13 Sep 2011 18:13:22 +0000 (+0200) Subject: Fix #98480 math when reading shared memory X-Git-Tag: accepted/trunk/20130322.191538~2767 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af8ff7274143ea04b0f17d1a1d34c1ee0f320c7e;p=platform%2Fupstream%2Fperl.git Fix #98480 math when reading shared memory 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. --- diff --git a/doio.c b/doio.c index cb77cf6..1edf8d2 100644 --- 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); diff --git a/t/io/shm.t b/t/io/shm.t index a450679..46bb2e1 100644 --- a/t/io/shm.t +++ b/t/io/shm.t @@ -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");