assert and simplify
This commit is contained in:
parent
93922d5b83
commit
5fd3750f16
@ -37,6 +37,7 @@
|
||||
#include "demangle.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user