From: Chris Hanson Date: Mon, 17 Apr 2017 01:47:28 +0000 (-0700) Subject: Return end-index of TO from bytevector-copy!. X-Git-Tag: mit-scheme-pucked-9.2.12~158^2~42 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=36dbb68b00906b19b9a0bc190ea643f8d1149bc1;p=mit-scheme.git Return end-index of TO from bytevector-copy!. --- diff --git a/src/microcode/bytevector.c b/src/microcode/bytevector.c index bf070b6bc..d25b33de9 100644 --- a/src/microcode/bytevector.c +++ b/src/microcode/bytevector.c @@ -150,18 +150,17 @@ DEFINE_PRIMITIVE ("bytevector-copy", Prim_bytevector_copy, 3, 3, 0) DEFINE_PRIMITIVE ("bytevector-copy!", Prim_bytevector_copyx, 5, 5, 0) { PRIMITIVE_HEADER (5); - { - unsigned long to_length; - uint8_t * to_v = (arg_bytevector (1, (&to_length))); - unsigned long to_start = (arg_ulong_index_integer (2, (to_length + 1))); - unsigned long from_length; - uint8_t * from_v = (arg_bytevector (3, (&from_length))); - unsigned long from_end = (arg_ulong_index_integer (5, (from_length + 1))); - unsigned long from_start = (arg_ulong_index_integer (4, (from_end + 1))); - unsigned long length = (from_end - from_start); - if ((to_length - to_start) < length) - error_bad_range_arg (5); - memmove ((to_v + to_start), (from_v + from_start), length); - } - PRIMITIVE_RETURN (UNSPECIFIC); + unsigned long to_length; + uint8_t * to_v = (arg_bytevector (1, (&to_length))); + unsigned long to_start = (arg_ulong_index_integer (2, (to_length + 1))); + unsigned long from_length; + uint8_t * from_v = (arg_bytevector (3, (&from_length))); + unsigned long from_end = (arg_ulong_index_integer (5, (from_length + 1))); + unsigned long from_start = (arg_ulong_index_integer (4, (from_end + 1))); + unsigned long length = (from_end - from_start); + unsigned long to_end = (to_start + length); + if (to_end > to_length) + error_bad_range_arg (5); + memmove ((to_v + to_start), (from_v + from_start), length); + PRIMITIVE_RETURN (ulong_to_integer (to_end)); }