Skip to content

Commit

Permalink
Demangle should not crash if out_size is 0.
Browse files Browse the repository at this point in the history
Co-authored-by: Sergiu Deitsch <[email protected]>
  • Loading branch information
martonka and sergiud authored Oct 28, 2024
1 parent 85050b1 commit 2c97007
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1350,9 +1350,11 @@ bool Demangle(const char* mangled, char* out, size_t out_size) {
return false;
}

size_t copy_size = std::min(n, out_size);
std::copy_n(unmangled.get(), copy_size, out);
out[copy_size - 1] = '\0'; // Ensure terminating null if n > out_size
if (out_size > 0) {
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
}
return status == 0;
#else
State state;
Expand Down

0 comments on commit 2c97007

Please sign in to comment.