summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mg.c4
-rw-r--r--t/lib/warnings/mg5
2 files changed, 7 insertions, 2 deletions
diff --git a/mg.c b/mg.c
index 268e0673f7..82f63c007d 100644
--- a/mg.c
+++ b/mg.c
@@ -1042,8 +1042,8 @@ int
Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg)
{
dVAR;
- STRLEN len, klen;
- const char *s = SvPV_const(sv,len);
+ STRLEN len = 0, klen;
+ const char *s = SvOK(sv) ? SvPV_const(sv,len) : "";
const char * const ptr = MgPV_const(mg,klen);
my_setenv(ptr, s);
diff --git a/t/lib/warnings/mg b/t/lib/warnings/mg
index c6d7506be2..2e2d4aa0f3 100644
--- a/t/lib/warnings/mg
+++ b/t/lib/warnings/mg
@@ -55,3 +55,8 @@ use warnings 'uninitialized';
length $3;
EXPECT
Use of uninitialized value $3 in length at - line 3.
+########
+# mg.c
+use warnings 'uninitialized';
+$ENV{FOO} = undef; # should not warn
+EXPECT