Do away with strncpy() and a fixed length buffer.
Jarkko Hietaniemi [Fri, 5 Jan 2001 15:40:42 +0000 (15:40 +0000)]
p4raw-id: //depot/perl@8332

utf8.c

diff --git a/utf8.c b/utf8.c
index 83e91fc..e82725e 100644 (file)
--- 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)