From af8ff7274143ea04b0f17d1a1d34c1ee0f320c7e Mon Sep 17 00:00:00 2001 From: Leon Timmermans Date: Tue, 13 Sep 2011 20:13:22 +0200 Subject: [PATCH] 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. --- doio.c | 3 ++- t/io/shm.t | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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"); -- 2.7.4