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

Conversation

lederernc
Copy link
Contributor

…r SYMBOL_INFO struct

We encountered an issue in a private code base where printing out the stack after an error would itself cause an access violation in debug builds on Windows. The issue ends up being that the SYMBOL_INFO struct was constructed with insufficient memory to store the symbol name, which far exceeded the allocated amount of memory.

The issue is resolved by allocating more stack memory to allow for the use of up to MAX_SYM_NAME characters in the name field.

@@ -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)

Copy link
Owner

@KjellKod KjellKod left a comment

Choose a reason for hiding this comment

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

Nice find!

@KjellKod KjellKod merged commit 9fb3e61 into KjellKod:master Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants