This reverts commit c65627a1fe3be7521fc232d633bb6df577f55269.
The test immediately after the new invalid symbol test was
failing on Windows. This was because when we called
VirtualQueryEx to get the region info for 0x0,
even if it succeeded we would call GetLastError.
Which must have picked up the last error that was set while
trying to lookup "not_an_address". Which happened to be 2.
("The system cannot find the file specified.")
To fix this only call GetLastError when we know VirtualQueryEx
has failed. (when it returns 0, which we were also checking for anyway)
Also convert memory region to an early return style
to make the logic clearer.
Actually, I would change the logic here a little bit to make it easier to read. Right now it is:
It should be:
This will make the function more readable, fixing the bug that you found, preserving most of its logic and keeping the single return.