From 3000a4ac8d2921025c6b310960b26edad0276629 Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Mon, 12 Feb 2018 15:56:01 +0000 Subject: [PATCH] Fix emulator strlcpy implementation (#298) --- emulator/strl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/emulator/strl.c b/emulator/strl.c index 42323a3ab2..b729892d9b 100644 --- a/emulator/strl.c +++ b/emulator/strl.c @@ -23,19 +23,22 @@ size_t strlcpy(char *dst, const char *src, size_t size) { if (size == 0) { - return 0; + return strlen(src); } - for (size_t i = 0; i < size - 1; i++) { + size_t i; + for (i = 0; i < size - 1; i++) { dst[i] = src[i]; if (src[i] == '\0') { - return i; + return i - 1; } } dst[size - 1] = '\0'; - return size - 2; + + while (src[i++] != '\0'); + return i - 1; } size_t strlcat(char *dst, const char *src, size_t size) {