1.1 --- a/templates/native/str.c Sat Feb 11 15:34:30 2017 +0100
1.2 +++ b/templates/native/str.c Sat Feb 11 16:04:40 2017 +0100
1.3 @@ -35,14 +35,15 @@
1.4 /* _data, other interpreted as string */
1.5 char *s = _data->strvalue;
1.6 char *o = other->strvalue;
1.7 - int n = _data->size + other->size;
1.8 + size_t ss = strlen(_data->strvalue), os = strlen(other->strvalue);
1.9 + int n = ss + os;
1.10 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
1.11
1.12 - memcpy(r, s, _data->size);
1.13 - memcpy(r + _data->size, o, other->size);
1.14 + memcpy(r, s, ss);
1.15 + memcpy(r + ss, o, os);
1.16
1.17 /* Return a new string. */
1.18 - return __new_str(r, n);
1.19 + return __new_str(r);
1.20 }
1.21
1.22 __attr __fn_native_str_str_chr(__attr __args[])
1.23 @@ -53,7 +54,7 @@
1.24 char *s = (char *) __ALLOCATE(2, sizeof(char));
1.25
1.26 s[0] = (char) n;
1.27 - return __new_str(s, 1);
1.28 + return __new_str(s);
1.29 }
1.30
1.31 __attr __fn_native_str_str_lt(__attr __args[])
1.32 @@ -97,14 +98,14 @@
1.33 __attr * const _data = &__args[1];
1.34
1.35 /* Return the new integer. */
1.36 - return __new_int(_data->size);
1.37 + return __new_int(strlen(_data->strvalue));
1.38 }
1.39
1.40 __attr __fn_native_str_str_nonempty(__attr __args[])
1.41 {
1.42 __attr * const _data = &__args[1];
1.43
1.44 - return _data->size ? __builtins___boolean_True : __builtins___boolean_False;
1.45 + return _data->strvalue[0] ? __builtins___boolean_True : __builtins___boolean_False;
1.46 }
1.47
1.48 __attr __fn_native_str_str_ord(__attr __args[])
1.49 @@ -146,7 +147,7 @@
1.50 for (from = istart, to = 0; from > iend; from += istep, to++)
1.51 sub[to] = s[from];
1.52
1.53 - return __new_str(sub, resultsize);
1.54 + return __new_str(sub);
1.55 }
1.56
1.57 /* Module initialisation. */