1.1 --- a/templates/native.c Tue Nov 22 17:36:39 2016 +0100
1.2 +++ b/templates/native.c Tue Nov 22 22:44:30 2016 +0100
1.3 @@ -1,7 +1,7 @@
1.4 #include <stdlib.h> /* calloc, exit, realloc */
1.5 #include <unistd.h> /* read, write */
1.6 #include <math.h> /* ceil, log10, pow */
1.7 -#include <string.h> /* strcmp, strlen */
1.8 +#include <string.h> /* strcmp, strncpy, strlen */
1.9 #include <stdio.h> /* snprintf */
1.10 #include "types.h"
1.11 #include "exceptions.h"
1.12 @@ -362,7 +362,7 @@
1.13 if (size >= capacity)
1.14 {
1.15 /* NOTE: Consider various restrictions on capacity increases. */
1.16 - n = data->capacity * 2;
1.17 + n = capacity ? capacity * 2 : 1;
1.18 data = realloc(data, __FRAGMENT_SIZE(n));
1.19 data->capacity = n;
1.20 }
1.21 @@ -441,8 +441,8 @@
1.22 __attr * const self = &__args[1];
1.23 /* self.__data__ interpreted as buffer */
1.24 __fragment *data = __load_via_object(self->value, __pos___data__).data;
1.25 - unsigned int size = 0, i, j;
1.26 - char *s;
1.27 + unsigned int size = 0, i, j, n;
1.28 + char *s, *o;
1.29
1.30 /* Calculate the size of the string. */
1.31 for (i = 0; i < data->size; i++)
1.32 @@ -452,8 +452,13 @@
1.33 s = calloc(size + 1, sizeof(char));
1.34
1.35 /* Build a single string from the buffer contents. */
1.36 - for (i = 0, j = 0; i < data->size; j += strlen(data->attrs[i].strvalue), i++)
1.37 - strcpy(s + j, data->attrs[i].strvalue);
1.38 + for (i = 0, j = 0; i < data->size; i++)
1.39 + {
1.40 + o = __load_via_object(data->attrs[i].value, __pos___data__).strvalue;
1.41 + n = strlen(o);
1.42 + strncpy(s + j, o, n);
1.43 + j += n;
1.44 + }
1.45
1.46 /* Return a new string. */
1.47 return __new_str(s);