From ac905caae96657928aa3abe60f692c5e57c920de Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Fri, 6 Jan 2023 23:03:34 +1100 Subject: [PATCH] AP_Common: add return to strncpy_noterm --- libraries/AP_Common/AP_Common.cpp | 4 +++- libraries/AP_Common/AP_Common.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Common/AP_Common.cpp b/libraries/AP_Common/AP_Common.cpp index cfc2e5379a..19c403c353 100644 --- a/libraries/AP_Common/AP_Common.cpp +++ b/libraries/AP_Common/AP_Common.cpp @@ -74,14 +74,16 @@ bool hex_to_uint8(uint8_t a, uint8_t &res) /* strncpy without the warning for not leaving room for nul termination */ -void strncpy_noterm(char *dest, const char *src, size_t n) +size_t strncpy_noterm(char *dest, const char *src, size_t n) { size_t len = strnlen(src, n); + size_t ret = len; // return value is length of src if (len < n) { // include nul term if it fits len++; } memcpy(dest, src, len); + return ret; } /** diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index f9632eec01..8bd64286da 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -158,7 +158,7 @@ bool hex_to_uint8(uint8_t a, uint8_t &res); // return the uint8 value of an asc /* strncpy without the warning for not leaving room for nul termination */ -void strncpy_noterm(char *dest, const char *src, size_t n); +size_t strncpy_noterm(char *dest, const char *src, size_t n); // return the numeric value of an ascii hex character int16_t char_to_hex(char a);