From: Vincent Pit Date: Tue, 20 Apr 2010 12:36:11 +0000 (+0200) Subject: Test if the name member is not NULL before cloning it X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=ed64994ebe8a4c0c1d4a23b9ebdce3ea39c098cf;p=perl%2Fmodules%2FSub-Op.git Test if the name member is not NULL before cloning it --- diff --git a/Op.xs b/Op.xs index 17fa468..6a71219 100644 --- 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; }