Blob Blame History Raw
From 389f3ef2fdfbba2c2816e7334a69a5f540c0a33d Mon Sep 17 00:00:00 2001
From: David Mitchell <davem@iabyn.com>
Date: Mon, 15 Dec 2014 16:14:13 +0000
Subject: [PATCH] EU::Constant: avoid 'uninit' warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The code generated by ExtUtils::Constant can look something like:

static int
constant (..., IV *iv_return) {
   switch (...) {
     case ...:
       *iv_return = ...;
       return PERL_constant_ISIV;
     ...
  }
}

{
    int type;
    IV iv;
    type = constant(..., &iv);
    switch (type) {
        case PERL_constant_ISIV:
            PUSHi(iv);
    ...
    }
}

and the compiler isn't clever enough to realise that the value of iv
is only used in the code path where its been set.

So initialise it to zero to shut gcc up. Ditto nv and pv.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
index 0dc9258..cf0e1ca 100644
--- a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
+++ b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
@@ -198,17 +198,17 @@ $XS_subname(sv)
 EOT
 
   if ($params->{IV}) {
-    $xs .= "	IV		iv;\n";
+    $xs .= "	IV		iv = 0; /* avoid uninit var warning */\n";
   } else {
     $xs .= "	/* IV\t\tiv;\tUncomment this if you need to return IVs */\n";
   }
   if ($params->{NV}) {
-    $xs .= "	NV		nv;\n";
+    $xs .= "	NV		nv = 0.0; /* avoid uninit var warning */\n";
   } else {
     $xs .= "	/* NV\t\tnv;\tUncomment this if you need to return NVs */\n";
   }
   if ($params->{PV}) {
-    $xs .= "	const char	*pv;\n";
+    $xs .= "	const char	*pv = NULL; /* avoid uninit var warning */\n";
   } else {
     $xs .=
       "	/* const char\t*pv;\tUncomment this if you need to return PVs */\n";
-- 
2.9.4