From 3fb280ff50f6bc9e74501574d9480776da0216cd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Apr 2021 16:53:29 +1000 Subject: [PATCH] AP_Common: added return to ExpandingString append --- libraries/AP_Common/ExpandingString.cpp | 11 +++++++---- libraries/AP_Common/ExpandingString.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Common/ExpandingString.cpp b/libraries/AP_Common/ExpandingString.cpp index c6a701eec3..bbb7473d0b 100644 --- a/libraries/AP_Common/ExpandingString.cpp +++ b/libraries/AP_Common/ExpandingString.cpp @@ -84,16 +84,19 @@ void ExpandingString::printf(const char *format, ...) /* print into the buffer, expanding if needed */ -void ExpandingString::append(const char *s, uint32_t len) +bool ExpandingString::append(const char *s, uint32_t len) { if (allocation_failed) { - return; + return false; } if (buflen - used < len && !expand(len)) { - return; + return false; + } + if (s != nullptr) { + memcpy(&buf[used], s, len); } - memcpy(&buf[used], s, len); used += len; + return true; } ExpandingString::~ExpandingString() diff --git a/libraries/AP_Common/ExpandingString.h b/libraries/AP_Common/ExpandingString.h index 573cb34313..7f4f23629c 100644 --- a/libraries/AP_Common/ExpandingString.h +++ b/libraries/AP_Common/ExpandingString.h @@ -36,8 +36,8 @@ public: // print into the string void printf(const char *format, ...) FMT_PRINTF(2,3); - // append data to the string - void append(const char *s, uint32_t len); + // append data to the string. s can be null for zero fill + bool append(const char *s, uint32_t len); // destructor ~ExpandingString();