From daadae488119c7a8cd28548e5d502abdafbf68e0 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 31 Mar 2025 03:34:21 +0200 Subject: Link d2d (#145) --- include/sized_string.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'include/sized_string.h') diff --git a/include/sized_string.h b/include/sized_string.h index 64b01a5a..c0670728 100644 --- a/include/sized_string.h +++ b/include/sized_string.h @@ -44,21 +44,25 @@ struct SizedString { void operator+=(const char *src) { if (src != nullptr) { - size_t destLen = strlen(mChars); - size_t copyLen = strlen(src); - - // Make sure copy length isnt more than destination length - if (destLen + copyLen + 1 >= Size) { - size_t tmpLen = Size - destLen; - copyLen = tmpLen - 1; - } + append(src); + } + } - strncpy(mChars + destLen, src, copyLen); + void append(const char *src) { + size_t destLen = strlen(mChars); + size_t copyLen = strlen(src); - // make sure string is null terminated - size_t offset = destLen + copyLen; - mChars[offset] = '\0'; + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= Size) { + size_t tmpLen = Size - destLen; + copyLen = tmpLen - 1; } + + strncpy(mChars + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; + mChars[offset] = '\0'; } bool operator==(const char *other) const { -- cgit v1.2.3