1.1 --- a/templates/native/buffer.c Mon Dec 12 00:33:33 2016 +0100
1.2 +++ b/templates/native/buffer.c Mon Dec 12 00:37:28 2016 +0100
1.3 @@ -16,7 +16,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 */
1.6
1.7 -#include <string.h> /* strcmp, strncpy, strlen */
1.8 +#include <string.h> /* strcmp, memcpy */
1.9 #include "native/common.h"
1.10 #include "types.h"
1.11 #include "exceptions.h"
1.12 @@ -32,11 +32,12 @@
1.13 /* _data interpreted as buffer */
1.14 __fragment *data = _data->seqvalue;
1.15 unsigned int size = 0, i, j, n;
1.16 - char *s, *o;
1.17 + char *s;
1.18 + __attr o;
1.19
1.20 /* Calculate the size of the string. */
1.21 for (i = 0; i < data->size; i++)
1.22 - size += strlen(__load_via_object(data->attrs[i].value, __pos___data__).strvalue);
1.23 + size += __load_via_object(data->attrs[i].value, __pos___data__).size;
1.24
1.25 /* Reserve space for a new string. */
1.26 s = (char *) __ALLOCATE(size + 1, sizeof(char));
1.27 @@ -44,14 +45,14 @@
1.28 /* Build a single string from the buffer contents. */
1.29 for (i = 0, j = 0; i < data->size; i++)
1.30 {
1.31 - o = __load_via_object(data->attrs[i].value, __pos___data__).strvalue;
1.32 - n = strlen(o);
1.33 - strncpy(s + j, o, n); /* does not null terminate but final byte should be zero */
1.34 + o = __load_via_object(data->attrs[i].value, __pos___data__);
1.35 + n = o.size;
1.36 + memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
1.37 j += n;
1.38 }
1.39
1.40 /* Return a new string. */
1.41 - return __new_str(s);
1.42 + return __new_str(s, size);
1.43 }
1.44
1.45 /* Module initialisation. */