From: Vincent Pit Date: Sat, 28 Feb 2009 15:18:58 +0000 (+0100) Subject: Check the number of allocated wizards in vmg_gensig() X-Git-Tag: v0.32~6 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=bc19b982e9997eb17ddf75dc235c0c6ac52d07bf Check the number of allocated wizards in vmg_gensig() --- diff --git a/Magic.xs b/Magic.xs index 0def957..1fa6354 100644 --- a/Magic.xs +++ b/Magic.xs @@ -313,6 +313,15 @@ typedef struct { START_MY_CXT +/* --- Error messages ------------------------------------------------------ */ + +STATIC const char vmg_invalid_wiz[] = "Invalid wizard object"; +STATIC const char vmg_invalid_sig[] = "Invalid numeric signature"; +STATIC const char vmg_wrongargnum[] = "Wrong number of arguments"; +STATIC const char vmg_toomanysigs[] = "Too many magic signatures used"; +STATIC const char vmg_argstorefailed[] = "Error while storing arguments"; +STATIC const char vmg_globstorefail[] = "Couldn't store global wizard information"; + /* --- Signatures ---------------------------------------------------------- */ #define SIG_MIN ((U16) 0u) @@ -330,6 +339,9 @@ STATIC U16 vmg_gensig(pTHX) { char buf[8]; dMY_CXT; + if (HvKEYS(MY_CXT.wizards) >= SIG_NBR) + croak(vmg_toomanysigs); + do { sig = SIG_NBR * Drand01() + SIG_MIN; } while (hv_exists(MY_CXT.wizards, buf, sprintf(buf, "%u", sig))); @@ -1048,13 +1060,6 @@ STATIC MGVTBL vmg_wizard_vtbl = { #endif /* MGf_LOCAL */ }; -STATIC const char vmg_invalid_wiz[] = "Invalid wizard object"; -STATIC const char vmg_invalid_sig[] = "Invalid numeric signature"; -STATIC const char vmg_wrongargnum[] = "Wrong number of arguments"; -STATIC const char vmg_toomanysigs[] = "Too many magic signatures used"; -STATIC const char vmg_argstorefailed[] = "Error while storing arguments"; -STATIC const char vmg_globstorefail[] = "Couldn't store global wizard information"; - STATIC U16 vmg_sv2sig(pTHX_ SV *sv) { #define vmg_sv2sig(S) vmg_sv2sig(aTHX_ (S)) IV sig; @@ -1305,7 +1310,6 @@ CODE: XSRETURN(1); } } else { - if (HvKEYS(MY_CXT.wizards) >= SIG_NBR) { croak(vmg_toomanysigs); } sig = vmg_gensig(); } @@ -1365,8 +1369,6 @@ OUTPUT: SV *gensig() PROTOTYPE: CODE: - dMY_CXT; - if (HvKEYS(MY_CXT.wizards) >= SIG_NBR) { croak(vmg_toomanysigs); } RETVAL = newSVuv(vmg_gensig()); OUTPUT: RETVAL