]> git.vpit.fr Git - perl/modules/Sub-Op.git/blobdiff - Op.xs
When cloning a config, eallocate one char more for the name
[perl/modules/Sub-Op.git] / Op.xs
diff --git a/Op.xs b/Op.xs
index 17fa468fc11fad06ff19b269e215cdb9acdf4541..d6dc30c3a9ebda75a9d9218b904bc1c2e58c89ec 100644 (file)
--- a/Op.xs
+++ b/Op.xs
@@ -146,15 +146,23 @@ 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 (orig->name) {
+  dupe->name   = PerlMemShared_malloc(len + 1);
+  Copy(orig->name, dupe->name, len, char);
+  ((char *) dupe->name)[len] = '\0';
+ } 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;
 }