diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend.c b/src/backend.c index f57707b..436dad4 100644 --- a/src/backend.c +++ b/src/backend.c @@ -150,17 +150,18 @@ backend_dup_strlist_n(char **strlist, int n) } /* Allocate space for the array of pointers (with NULL terminator) and * then the string data. */ - ret = malloc(((i + 1) * sizeof(char *)) + l); + ret = malloc(((n + 1) * sizeof(char *)) + l); if (ret != NULL) { /* Figure out where the string data will start. */ - s = (char *) &ret[i + 1]; + s = (char *) ret; + s += ((n + 1) * sizeof(char *)); for (i = 0; i < n; i++) { /* Set the address of this string, copy the data * around, and then prepare the address of the next * string. */ ret[i] = s; strcpy(s, strlist[i]); - s += (strlen(s) + 1); + s += (strlen(strlist[i]) + 1); } /* NULL-terminate the array. */ ret[i] = NULL; |
