From 1af5a42e566da1e615abae7868ae7a10260ce0b8 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 24 Nov 2018 08:13:23 +0000 Subject: bugfix: rounding error in stralloc_reverse_blocks --- src/libstddjb/stralloc_reverse_blocks.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstddjb/stralloc_reverse_blocks.c b/src/libstddjb/stralloc_reverse_blocks.c index 86b7fc4..731d635 100644 --- a/src/libstddjb/stralloc_reverse_blocks.c +++ b/src/libstddjb/stralloc_reverse_blocks.c @@ -10,8 +10,9 @@ void stralloc_reverse_blocks (stralloc *sa, size_t size) char tmp[size] ; for (; i < n ; i++) { + size_t k = sa->len - (i + 1) * size ; memcpy(tmp, sa->s + i * size, size) ; - memcpy(sa->s + i * size, sa->s + (2*n - 1 - i) * size, size) ; - memcpy(sa->s + (2*n - 1 - i) * size, tmp, size) ; + memcpy(sa->s + i * size, sa->s + k, size) ; + memcpy(sa->s + k, tmp, size) ; } } -- cgit v1.2.3