Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 2c97007

Browse files
martonkasergiud
andauthored
Demangle should not crash if out_size is 0.
Co-authored-by: Sergiu Deitsch <[email protected]>
1 parent 85050b1 commit 2c97007

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/demangle.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,11 @@ bool Demangle(const char* mangled, char* out, size_t out_size) {
13501350
return false;
13511351
}
13521352

1353-
size_t copy_size = std::min(n, out_size);
1354-
std::copy_n(unmangled.get(), copy_size, out);
1355-
out[copy_size - 1] = '\0'; // Ensure terminating null if n > out_size
1353+
if (out_size > 0) {
1354+
std::size_t copy_size = std::min(n, out_size - 1);
1355+
std::copy_n(unmangled.get(), copy_size, out);
1356+
out[copy_size] = '\0'; // Ensure terminating null if n > out_size
1357+
}
13561358
return status == 0;
13571359
#else
13581360
State state;

0 commit comments

Comments
 (0)