summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doio.c2
-rw-r--r--t/io/shm.t18
2 files changed, 18 insertions, 2 deletions
diff --git a/doio.c b/doio.c
index df6e62c0f3..439f2d096a 100644
--- a/doio.c
+++ b/doio.c
@@ -3251,7 +3251,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
else {
STRLEN len;
- const char *mbuf = SvPV_const(mstr, len);
+ const char *mbuf = SvPVbyte(mstr, len);
const I32 n = ((I32)len > msize) ? msize : (I32)len;
Copy(mbuf, shm + mpos, n, char);
if (n < msize)
diff --git a/t/io/shm.t b/t/io/shm.t
index 3feb3032d9..ced92a6186 100644
--- a/t/io/shm.t
+++ b/t/io/shm.t
@@ -53,7 +53,7 @@ if (not defined $key) {
}
}
else {
- plan(tests => 15);
+ plan(tests => 21);
pass('acquired shared mem');
}
@@ -88,3 +88,19 @@ tie $ct, 'Counted';
shmread $key, $ct, 0, 1;
is($fetch, 1, "shmread FETCH once");
is($store, 1, "shmread STORE once");
+
+{
+ # check reading into an upgraded buffer is sane
+ my $text = "\xC0\F0AB";
+ ok(shmwrite($key, $text, 0, 4), "setup text");
+ my $rdbuf = "\x{101}";
+ ok(shmread($key, $rdbuf, 0, 4), "read it back");
+ is($rdbuf, $text, "check we got back the expected");
+
+ # check writing from an upgraded buffer
+ utf8::upgrade(my $utext = $text);
+ ok(shmwrite($key, $utext, 0, 4), "setup text (upgraded source)");
+ $rdbuf = "";
+ ok(shmread($key, $rdbuf, 0, 4), "read it back (upgraded source)");
+ is($rdbuf, $text, "check we got back the expected (upgraded source)");
+}