string: fix strncpy and strncat buffer limit check

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-10-01 23:19:39 +02:00
parent d7a44c2929
commit 02c531e2a8

View File

@ -685,9 +685,9 @@ namespace stdex
assert(src || !count_src); assert(src || !count_src);
for (size_t i = 0; ; ++i) for (size_t i = 0; ; ++i)
{ {
if (i > count_dst) if (i >= count_dst)
return i; return i;
if (i > count_src) { if (i >= count_src) {
dst[i] = 0; dst[i] = 0;
return i; return i;
} }
@ -758,9 +758,9 @@ namespace stdex
assert(src || !count_src); assert(src || !count_src);
for (size_t i = 0, j = stdex::strnlen<T1>(dst, count_dst); ; ++i, ++j) for (size_t i = 0, j = stdex::strnlen<T1>(dst, count_dst); ; ++i, ++j)
{ {
if (j > count_dst) if (j >= count_dst)
return j; return j;
if (i > count_src) { if (i >= count_src) {
dst[j] = 0; dst[j] = 0;
return j; return j;
} }