summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/params.c17
-rw-r--r--Src/string.c13
2 files changed, 26 insertions, 4 deletions
diff --git a/Src/params.c b/Src/params.c
index 0894241b9..19a8c291d 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2060,6 +2060,7 @@ getstrvalue(Value v)
 {
     char *s, **ss;
     char buf[BDIGBUFSIZE];
+    int len = -1;
 
     if (!v)
 	return hcalloc(1);
@@ -2237,22 +2238,30 @@ getstrvalue(Value v)
 	return s;
 
     if (v->start < 0) {
-	v->start += strlen(s);
+	len = strlen(s);
+	v->start += len;
 	if (v->start < 0)
 	    v->start = 0;
     }
     if (v->end < 0) {
-	v->end += strlen(s);
+	if (len < 0)
+	    len = strlen(s);
+	v->end += len;
 	if (v->end >= 0) {
 	    char *eptr = s + v->end;
 	    if (*eptr)
 		v->end += MB_METACHARLEN(eptr);
 	}
     }
-    s = (v->start > (int)strlen(s)) ? dupstring("") : dupstring(s + v->start);
+
+    if (len < 0)
+	len = strlen(s);
+    s = (v->start > len) ? dupstring("") :
+	dupstring_wlen(s + v->start, len - v->start);
+
     if (v->end <= v->start)
 	s[0] = '\0';
-    else if (v->end - v->start <= (int)strlen(s))
+    else if (v->end - v->start <= len - v->start)
 	s[v->end - v->start] = '\0';
 
     return s;
diff --git a/Src/string.c b/Src/string.c
index 04e7446c9..b46ea60cf 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -43,6 +43,19 @@ dupstring(const char *s)
 
 /**/
 mod_export char *
+dupstring_wlen(const char *s, unsigned len)
+{
+    char *t;
+
+    if (!s)
+	return NULL;
+    t = (char *) zhalloc(len + 1);
+    strcpy(t, s);
+    return t;
+}
+
+/**/
+mod_export char *
 ztrdup(const char *s)
 {
     char *t;