Change: [Win32] don't allocate 192KiB of memory on the stack on crash #11240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
While looking at the Windows crashlog dialog, I noticed it was allocating a lot of memory on the stack. So I looked at JGRPP, and got some inspiration how to solve it properly.
Description
Heap is out of the question, as it might be corrupted. Allocating this much on stack is silly.
So instead, allocate virtual pages to write the information in.
While at it, also added the savegame filename to the dialog, and as they are (now) always set, remove any conditional around them. This simplifies the code a lot, as now it can be printed by a single snprint.
Limitations
Where JGRPP took the approach of: better allocate too much memory than run out of a buffer, I went for: let's do the math correctly, and make sure all buffers fit, while making them nice and snugly. This means the buffers are on the byte of the correct size.
JGRPP's approach might be more robust; although I am pretty sure my math adds up, and should be safe. I hope.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.