about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/params.c4
-rw-r--r--Src/string.c17
2 files changed, 19 insertions, 2 deletions
diff --git a/Src/params.c b/Src/params.c
index 19a8c291d..3f0179267 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2432,8 +2432,8 @@ assignstrvalue(Value v, char *val, int flags)
 	    char *z, *x;
 	    int zlen;
 
-	    z = dupstring(v->pm->gsu.s->getfn(v->pm));
-	    zlen = strlen(z);
+	    z = dupstring_glen(v->pm->gsu.s->getfn(v->pm), (unsigned*) &zlen);
+
 	    if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
 		v->start--, v->end--;
 	    if (v->start < 0) {
diff --git a/Src/string.c b/Src/string.c
index b46ea60cf..a8da14fe0 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -41,6 +41,8 @@ dupstring(const char *s)
     return t;
 }
 
+/* Duplicate string on heap when length is known */
+
 /**/
 mod_export char *
 dupstring_wlen(const char *s, unsigned len)
@@ -54,6 +56,21 @@ dupstring_wlen(const char *s, unsigned len)
     return t;
 }
 
+/* Duplicate string on heap, returning length of string */
+
+/**/
+mod_export char *
+dupstring_glen(const char *s, unsigned *len_ret)
+{
+    char *t;
+
+    if (!s)
+	return NULL;
+    t = (char *) zhalloc((*len_ret = strlen((char *)s)) + 1);
+    strcpy(t, s);
+    return t;
+}
+
 /**/
 mod_export char *
 ztrdup(const char *s)