[Skiboot] [PATCH 2/2] libc/memmove: Correct the buffer overlap condition

Neelesh Gupta neelegup at linux.vnet.ibm.com
Wed Feb 4 20:52:09 AEDT 2015


Signed-off-by: Neelesh Gupta <neelegup at linux.vnet.ibm.com>
---
 libc/string/memmove.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index 3acf1a9..844f300 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -21,15 +21,14 @@ memmove(void *dest, const void *src, size_t n)
 	int i;
 
 	/* Do the buffers overlap in a bad way? */
-	if (src < dest && src + n >= dest) {
+	if (src < dest && src + n - 1 >= dest) {
 		/* Copy from end to start */
 		cdest = dest + n - 1;
 		csrc = src + n - 1;
 		for (i = 0; i < n; i++) {
 			*cdest-- = *csrc--;
 		}
-	}
-	else {
+	} else {
 		/* Normal copy is possible */
 		cdest = dest;
 		csrc = src;



More information about the Skiboot mailing list