diff --git a/src/demangle.cc b/src/demangle.cc index 8e5189d..8f4db36 100644 --- a/src/demangle.cc +++ b/src/demangle.cc @@ -37,6 +37,7 @@ #include "demangle.h" #include +#include #include #include @@ -1351,10 +1352,11 @@ bool Demangle(const char* mangled, char* out, size_t out_size) { } if (out_size > 0) { + assert(n > 1); // n is the size of the allocated buffer, not the length of the string. // Therefore, it includes the terminating zero (and possibly additional // space). - std::size_t copy_size = std::min(n - 1, out_size - 1); + std::size_t copy_size = std::min(n, out_size) - 1; std::copy_n(unmangled.get(), copy_size, out); out[copy_size] = '\0'; // Ensure terminating null if n > out_size }