Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with stacktrace_windows not allocating sufficient memory fo… #334

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/stacktrace_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace {

DWORD64 displacement64;
DWORD displacement;
char symbol_buffer[sizeof(SYMBOL_INFO) + 256];
char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(symbol_buffer);
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;
Expand All @@ -120,7 +120,7 @@ namespace {
std::string lineInformation;
std::string callInformation;
if (SymFromAddr(GetCurrentProcess(), addr, &displacement64, symbol)) {
callInformation.append(" ").append({std::string(symbol->Name), symbol->NameLen});
Copy link
Owner

@KjellKod KjellKod Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason append was used before and not the std:: constructor was that I was not 100% sure the symbol would not contain null characters. The append function which is almost identical to the constructor for these arguments declare that null characters are fine to add.

Are you sure that the symbol string will never have null characters? Is this documented?
https://en.cppreference.com/w/cpp/string/basic_string/append (see: 4)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore that. I see now that the declaration for std::string constructor (4) is identical.
https://en.cppreference.com/w/cpp/string/basic_string/basic_string

So this change is slightly better as it creates fewer copies (potentially)

callInformation.append(" ").append(std::string(symbol->Name, symbol->NameLen));
if (SymGetLineFromAddr64(GetCurrentProcess(), addr, &displacement, &line)) {
lineInformation.append("\t").append(line.FileName).append(" L: ");
lineInformation.append(std::to_string(line.LineNumber));
Expand Down