Opcode: fix 'null argument' warning
authorDavid Mitchell <davem@iabyn.com>
Wed, 13 Nov 2013 17:30:10 +0000 (17:30 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Nov 2013 17:38:43 +0000 (17:38 +0000)
HvNAME_get() can return NULL, and strNE() wants non-null args.

[
As a side note: on debugging builds this line

    if (strNE(HvNAME_get(hv),"main")) {

macro-expands into an 18,000 character line (!) due to the fact that
HvNAME_get() is quite a big expansion under debugging, and strNE expands to
strlen, which under gcc expands to a huge macro (which is mainly lots of
different compile-time alternatives depending on which of its args are
constants), that references its args several times.
]

ext/Opcode/Opcode.pm
ext/Opcode/Opcode.xs

index 48b6ae0..a48b01d 100644 (file)
@@ -6,7 +6,7 @@ use strict;
 
 our($VERSION, @ISA, @EXPORT_OK);
 
-$VERSION = "1.26";
+$VERSION = "1.27";
 
 use Carp;
 use Exporter ();
index 4e6af8d..386dddf 100644 (file)
@@ -257,11 +257,13 @@ _safe_pkg_prep(Package)
     SV *Package
 PPCODE:
     HV *hv; 
+    char *hvname;
     ENTER;
    
     hv = gv_stashsv(Package, GV_ADDWARN); /* should exist already      */
 
-    if (strNE(HvNAME_get(hv),"main")) {
+    hvname = HvNAME_get(hv);
+    if (!hvname || strNE(hvname, "main")) {
         /* make it think it's in main:: */
        hv_name_set(hv, "main", 4, 0);
         (void) hv_store(hv,"_",1,(SV *)PL_defgv,0);  /* connect _ to global */