From 3182bdf1e39559179c8e7f97ea9eb5f4bff0ef7f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 5 Jul 2019 07:45:58 -0700 Subject: replace: deal with overlapping. * buf.c (replace_buf): In the same-type case, use memmove rather than memcpy in case the objects overlap, so we don't invoke C undefined behavior. * lib.c (replace_str, replace_vec): Likewise. * txr.1: Specify that if the replacement sequence overlaps with the target range of the destination sequence, or with any portion that has to be relocated if range changes size, then the behavior is unspecified. --- buf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'buf.c') diff --git a/buf.c b/buf.c index d95a9033..928eaece 100644 --- a/buf.c +++ b/buf.c @@ -339,7 +339,7 @@ val replace_buf(val buf, val items, val from, val to) if (zerop(len_it)) return buf; if (bufp(items)) { - memcpy(buf->b.data + c_num(from), items->b.data, c_num(len_it)); + memmove(buf->b.data + c_num(from), items->b.data, c_num(len_it)); } else { seq_iter_t item_iter; seq_iter_init(self, &item_iter, items); -- cgit v1.2.3