Bugfixes:

- Avoid unnecessary calls to `strlen`
- Type check the `fill` parameter to `make-string`
This commit is contained in:
Justin Ethier 2017-10-27 13:01:04 +00:00
parent 4a77296ddf
commit 6aaa600ebc

View file

@ -951,11 +951,16 @@
"(void *data, int argc, closure _, object k, object count, object fill)"
" object s = NULL;
char ch_buf[5];
char_type c;
int buflen, num_cp, len;
Cyc_check_int(data, count);
char_type c = obj_obj2char(fill);
Cyc_utf8_encode_char(ch_buf, 5, c);
int num_cp = obj_obj2int(count);
int len = num_cp * strlen(ch_buf);
if (!obj_is_char(fill)) {
Cyc_rt_raise2(data, \"Expected character buf received\", fill);
}
c = obj_obj2char(fill);
buflen = Cyc_utf8_encode_char(ch_buf, 5, c);
num_cp = obj_obj2int(count);
len = num_cp * buflen;
if (len >= MAX_STACK_OBJ) {
int heap_grown;
s = gc_alloc(((gc_thread_data *)data)->heap,
@ -982,7 +987,7 @@
memset(((string_type *)s)->str, ch_buf[0], len);
} else {
char *buf = ((string_type *)s)->str;
int bi, si, slen = strlen(ch_buf);
int bi, si, slen = buflen;
for (bi = 0, si = 0; bi < len; bi++, si++) {
buf[bi] = ch_buf[si % slen];
}