This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PL_inf/PL_nan need different export with C++
[perl5.git] / util.c
diff --git a/util.c b/util.c
index 0f5533e..a69ddad 100644 (file)
--- a/util.c
+++ b/util.c
@@ -522,10 +522,17 @@ Free_t   Perl_mfree (Malloc_t where)
 
 #endif
 
-/* copy a string up to some (non-backslashed) delimiter, if any */
+/* copy a string up to some (non-backslashed) delimiter, if any.
+ * With allow_escape, converts \<delimiter> to <delimiter>, while leaves
+ * \<non-delimiter> as-is.
+ * Returns the position in the src string of the closing delimiter, if
+ * any, or returns fromend otherwise.
+ * This is the internal implementation for Perl_delimcpy and
+ * Perl_delimcpy_no_escape.
+ */
 
 static char *
-S_delimcpy(char *to, const char *toend, const char *from,
+S_delimcpy_intern(char *to, const char *toend, const char *from,
           const char *fromend, int delim, I32 *retlen,
           const bool allow_escape)
 {
@@ -534,7 +541,7 @@ S_delimcpy(char *to, const char *toend, const char *from,
     PERL_ARGS_ASSERT_DELIMCPY;
 
     for (tolen = 0; from < fromend; from++, tolen++) {
-       if (allow_escape && *from == '\\') {
+       if (allow_escape && *from == '\\' && from + 1 < fromend) {
            if (from[1] != delim) {
                if (to < toend)
                    *to++ = *from;
@@ -558,7 +565,7 @@ Perl_delimcpy(char *to, const char *toend, const char *from, const char *fromend
 {
     PERL_ARGS_ASSERT_DELIMCPY;
 
-    return S_delimcpy(to, toend, from, fromend, delim, retlen, 1);
+    return S_delimcpy_intern(to, toend, from, fromend, delim, retlen, 1);
 }
 
 char *
@@ -567,7 +574,7 @@ Perl_delimcpy_no_escape(char *to, const char *toend, const char *from,
 {
     PERL_ARGS_ASSERT_DELIMCPY_NO_ESCAPE;
 
-    return S_delimcpy(to, toend, from, fromend, delim, retlen, 0);
+    return S_delimcpy_intern(to, toend, from, fromend, delim, retlen, 0);
 }
 
 /*