This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix NUL-termination bug in delimcpy()
[perl5.git] / util.c
diff --git a/util.c b/util.c
index 2ee9c0e..fc24583 100644 (file)
--- a/util.c
+++ b/util.c
@@ -302,14 +302,13 @@ I32 *retlen;
                from++;
            }
        }
-       else if (*from == delim) {
-           if (to < toend)
-               *to = '\0';
+       else if (*from == delim)
            break;
-       }
        if (to < toend)
            *to++ = *from;
     }
+    if (to < toend)
+       *to = '\0';
     *retlen = tolen;
     return from;
 }