The specific problem Clinton mentioned is yet another infant mortality
problem, this time in string_concat. I don't know what the current decision
is on handling these situations, but this one can be avoided by optimising
the code anyway. If the transcoding is done before making the result string,
we know the actual length, instead of using the maximum possible.

I haven't yet looked to see why basic needs to transcode string anyway.

--
Peter Gibbs
EmKel Systems

Index: string.c
===================================================================
RCS file: /home/perlcvs/parrot/string.c,v
retrieving revision 1.68
diff -u -r1.68 string.c
--- string.c    12 Apr 2002 01:40:28 -0000      1.68
+++ string.c    14 Apr 2002 18:45:54 -0000
@@ -283,14 +283,14 @@

     if (a != NULL && a->strlen != 0) {
         if (b != NULL && b->strlen != 0) {
-            result = string_make(interpreter, NULL, a->bufused +
-                                 b->strlen * a->encoding->max_bytes,
-                                 a->encoding, 0, a->type);
-            mem_sys_memcopy(result->bufstart, a->bufstart, a->bufused);
+            /* transcode first so we know the length and avoid infanticide
*/
             if (a->type != b->type || a->encoding != b->encoding) {
                 b = string_transcode(interpreter, b, a->encoding, a->type,
                                      NULL);
             }
+            result = string_make(interpreter, NULL, a->bufused +
b->bufused,
+                                 a->encoding, 0, a->type);
+            mem_sys_memcopy(result->bufstart, a->bufstart, a->bufused);
             mem_sys_memcopy((void *)((ptrcast_t)result->bufstart +
a->bufused),
                             b->bufstart, b->bufused);
             result->strlen = a->strlen + b->strlen;


Reply via email to