]> git.vpit.fr Git - perl/modules/Sub-Op.git/commitdiff
Test if the name member is not NULL before cloning it
authorVincent Pit <vince@profvince.com>
Tue, 20 Apr 2010 12:36:11 +0000 (14:36 +0200)
committerVincent Pit <vince@profvince.com>
Tue, 20 Apr 2010 12:36:11 +0000 (14:36 +0200)
Op.xs

diff --git a/Op.xs b/Op.xs
index 17fa468fc11fad06ff19b269e215cdb9acdf4541..6a71219845dace3c81e3860b18970d4fddd3e3fe 100644 (file)
--- a/Op.xs
+++ b/Op.xs
@@ -146,15 +146,22 @@ void sub_op_register(pTHX_ const sub_op_config_t *c, U32 flags) {
 }
 
 sub_op_config_t *sub_op_dup(pTHX_ const sub_op_config_t *orig) {
+ STRLEN len;
  sub_op_config_t *dupe = PerlMemShared_malloc(sizeof *dupe);
 
- dupe->namelen = orig->namelen;
- dupe->name    = PerlMemShared_malloc(dupe->namelen);
- Copy(orig->name, dupe->name, dupe->namelen, char);
+ len           = orig->namelen;
+ if (len && orig->name) {
+  dupe->name   = PerlMemShared_malloc(len);
+  Copy(orig->name, dupe->name, len, char);
+ } else {
+  dupe->name   = NULL;
+ }
+ dupe->namelen = len;
+
 
- dupe->pp      = orig->pp;
- dupe->check   = orig->check;
- dupe->ud      = orig->ud;
+ dupe->pp    = orig->pp;
+ dupe->check = orig->check;
+ dupe->ud    = orig->ud;
 
  return dupe;
 }