commit 1af5a42e566da1e615abae7868ae7a10260ce0b8
parent 661329653329949929b043f5fc45821aa314face
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Sat, 24 Nov 2018 08:13:23 +0000
bugfix: rounding error in stralloc_reverse_blocks
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git 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) ;
}
}