From: Jarkko Hietaniemi Date: Fri, 5 Jan 2001 15:40:42 +0000 (+0000) Subject: Do away with strncpy() and a fixed length buffer. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf1fed83f9a0d78ad078e497a12a4e988adb9031;p=p5sagit%2Fp5-mst-13.2.git Do away with strncpy() and a fixed length buffer. p4raw-id: //depot/perl@8332 --- diff --git a/utf8.c b/utf8.c index 83e91fc..e82725e 100644 --- a/utf8.c +++ b/utf8.c @@ -1115,7 +1115,7 @@ SV* Perl_swash_init(pTHX_ char* pkg, char* name, SV *listsv, I32 minbits, I32 none) { SV* retval; - char tmpbuf[256]; + SV* tokenbufsv = sv_2mortal(NEWSV(0,0)); dSP; if (!gv_stashpv(pkg, 0)) { /* demand load utf8 */ @@ -1137,8 +1137,9 @@ Perl_swash_init(pTHX_ char* pkg, char* name, SV *listsv, I32 minbits, I32 none) SAVEI32(PL_hints); PL_hints = 0; save_re_context(); - if (PL_curcop == &PL_compiling) /* XXX ought to be handled by lex_start */ - strncpy(tmpbuf, PL_tokenbuf, sizeof tmpbuf); + if (PL_curcop == &PL_compiling) + /* XXX ought to be handled by lex_start */ + sv_setpv(tokenbufsv, PL_tokenbuf); if (call_method("SWASHNEW", G_SCALAR)) retval = newSVsv(*PL_stack_sp--); else @@ -1146,7 +1147,10 @@ Perl_swash_init(pTHX_ char* pkg, char* name, SV *listsv, I32 minbits, I32 none) LEAVE; POPSTACK; if (PL_curcop == &PL_compiling) { - strncpy(PL_tokenbuf, tmpbuf, sizeof tmpbuf); + STRLEN len; + char* pv = SvPV(tokenbufsv, len); + + Copy(pv, PL_tokenbuf, len+1, char); PL_curcop->op_private = PL_hints; } if (!SvROK(retval) || SvTYPE(SvRV(retval)) != SVt_PVHV)