This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: don't use strcpy()
authorDavid Mitchell <davem@iabyn.com>
Tue, 24 May 2016 22:45:48 +0000 (23:45 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 24 May 2016 22:54:24 +0000 (23:54 +0100)
A recent commit added a strcpy() to locale.c.

This is Frowned Upon, and was making porting/libperl.t fail.

Since PL_strxfrm_min_char appears to be a 3-byte buffer, I've just changed
it to manually copy 3 individual bytes - which is probably more efficient
than a full-blown Copy(). But I haven't looked closely at whether this is
correct - this is more of quick fix to get smoking passing again.

locale.c

index 97cc735..67843d2 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -1525,7 +1525,9 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
                     || strLT(x         + COLLXFRM_HDR_LEN,
                              cur_min_x + COLLXFRM_HDR_LEN))
                 {
-                    strcpy(PL_strxfrm_min_char, cur_source);
+                    PL_strxfrm_min_char[0] = cur_source[0];
+                    PL_strxfrm_min_char[1] = cur_source[1];
+                    PL_strxfrm_min_char[2] = cur_source[2];
                     cur_min_x = x;
 #ifdef DEBUGGING
                     cur_min_cp = j;