1.1 --- a/templates/native.c Tue Dec 06 18:18:47 2016 +0100
1.2 +++ b/templates/native.c Tue Dec 06 20:32:33 2016 +0100
1.3 @@ -663,7 +663,7 @@
1.4 /* Produce an exception if the operation failed. */
1.5
1.6 if (f == NULL)
1.7 - __raise_io_error(errno);
1.8 + __raise_io_error(__new_int(errno));
1.9 else
1.10 {
1.11 attr.context = 0;
1.12 @@ -682,18 +682,19 @@
1.13 int to_read = __load_via_object(n->value, __pos___data__).intvalue;
1.14 void *buf[to_read + 1];
1.15 ssize_t have_read;
1.16 + char *s;
1.17
1.18 errno = 0;
1.19 have_read = read(i, buf, to_read);
1.20
1.21 if (have_read == -1)
1.22 - __raise_io_error(errno);
1.23 + __raise_io_error(__new_int(errno));
1.24 else
1.25 {
1.26 - /* Zero terminate the string. */
1.27 -
1.28 - buf[have_read] = 0;
1.29 - return __new_str((char *) buf);
1.30 + /* Reserve space for a new string. */
1.31 + s = __ALLOCATE(have_read + 1, 1);
1.32 + strncpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
1.33 + return __new_str(s);
1.34 }
1.35 }
1.36