From 02c531e2a8caae7030eec6c61862ea905d8e49de Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sun, 1 Oct 2023 23:19:39 +0200 Subject: [PATCH] string: fix strncpy and strncat buffer limit check Signed-off-by: Simon Rozman --- include/stdex/string.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 9e9933d5c..789e32ae4 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -685,9 +685,9 @@ namespace stdex assert(src || !count_src); for (size_t i = 0; ; ++i) { - if (i > count_dst) + if (i >= count_dst) return i; - if (i > count_src) { + if (i >= count_src) { dst[i] = 0; return i; } @@ -758,9 +758,9 @@ namespace stdex assert(src || !count_src); for (size_t i = 0, j = stdex::strnlen(dst, count_dst); ; ++i, ++j) { - if (j > count_dst) + if (j >= count_dst) return j; - if (i > count_src) { + if (i >= count_src) { dst[j] = 0; return j; }