diff --git a/libraries/AP_HAL/Util.cpp b/libraries/AP_HAL/Util.cpp index 4b67df77d5..8c66a01976 100644 --- a/libraries/AP_HAL/Util.cpp +++ b/libraries/AP_HAL/Util.cpp @@ -52,9 +52,12 @@ int AP_HAL::Util::snprintf(char* str, size_t size, const char *format, ...) int AP_HAL::Util::vsnprintf(char* str, size_t size, const char *format, va_list ap) { - BufferPrinter buf(str, size); + if (size == 0) { + return 0; + } + BufferPrinter buf(str, size-1); print_vprintf(&buf, format, ap); - // null terminate if possible + // null terminate int ret = buf._offs; buf.write(0); return ret;