mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 22:29:16 +02:00
string-ref and string-set! will raise an error on the trailing null byte.
This commit is contained in:
parent
6145922589
commit
cc5d5d573c
2 changed files with 5 additions and 1 deletions
4
eval.c
4
eval.c
|
@ -1469,6 +1469,8 @@ sexp sexp_string_utf8_index_ref (sexp ctx, sexp self, sexp_sint_t n, sexp str, s
|
|||
sexp_assert_type(ctx, sexp_fixnump, SEXP_FIXNUM, i);
|
||||
off = sexp_string_index_to_offset(ctx, self, n, str, i);
|
||||
if (sexp_exceptionp(off)) return off;
|
||||
if (sexp_unbox_fixnum(off) >= sexp_string_length(str))
|
||||
return sexp_user_exception(ctx, self, "string-ref: index out of range", i);
|
||||
return sexp_string_utf8_ref(ctx, str, off);
|
||||
}
|
||||
|
||||
|
@ -1522,6 +1524,8 @@ sexp sexp_string_utf8_index_set (sexp ctx, sexp self, sexp_sint_t n, sexp str, s
|
|||
sexp_assert_type(ctx, sexp_charp, SEXP_CHAR, ch);
|
||||
off = sexp_string_index_to_offset(ctx, self, n, str, i);
|
||||
if (sexp_exceptionp(off)) return off;
|
||||
if (sexp_unbox_fixnum(off) >= sexp_string_length(str))
|
||||
return sexp_user_exception(ctx, self, "string-set!: index out of range", i);
|
||||
sexp_string_utf8_set(ctx, str, off, ch);
|
||||
return SEXP_VOID;
|
||||
}
|
||||
|
|
2
sexp.c
2
sexp.c
|
@ -894,7 +894,7 @@ sexp sexp_string_index_to_offset (sexp ctx, sexp self, sexp_sint_t n, sexp str,
|
|||
limit = sexp_string_length(str);
|
||||
for (j=0, i=sexp_unbox_fixnum(index); i>0 && j<limit; i--)
|
||||
j += sexp_utf8_initial_byte_count(p[j]);
|
||||
if (i>0)
|
||||
if (i != 0)
|
||||
return sexp_user_exception(ctx, self, "string-index->offset: index out of range", index);
|
||||
return sexp_make_fixnum(j);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue