C++: ReadProcessMemory() causes crashes [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
ReadProcessMemory() seems to crash my program, when it reads undefined(?) memory.
Well my question is, how can I check if the address is undefined or whatever before I use ReadProcessMemory to avaoid crashes?
The errormessage btw:
Unhandled exception at 0x00ce1c70 in Program.exe: 0xC0000005:
Access violation writing location 0x00e3f000.

The crash is not coming because you are reading invalid / undefined memory, it is coming because you passed an invalid buffer into ReadProcessMemory. Note that the the error message says violation writing, not reading.
You need to make sure the buffer you are passing is appropriately sized for the data amount that you are requesting. If you post the code used to call the method we may be able to help spot the error

Related

Exception 0xC0000409 (stack buffer overflow) when using dynamic_pointer_cast [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm experiencing a crash when trying to dynamic_pointer_cast a shared point of type A to type B.
Type B is not related to type A and I'd expect an empty shared_ptr but instead, the exception above is raised.
Is there any scenario where it isn't safe to use dynamic_pointer_cast?
Exception raised here:
Using MSVC 14.16.27023
std::dynamic_pointer_cast requires that the conversion of U* (source) to T* (destination) is well formed. If it isn't then you have undefined behavior. If you want to get a null pointer like you would from dynamic_cast then you are going to have to write your own version that will do this.
Another option is test the result of
dynamic_cast<decltype(destination_ptr.get())>(source_ptr.get())
And if that succeeds then call std::dynamic_pointer_cast else return a null pointer.

Why aren't we given more information about Segmentation Fault during runtime? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Whenever I get a Segmentation Fault error, I know that somewhere I am accessing memory that "does not belong to me".
In some nonobvious cases, I have to rely on debugging tools such as a profiler (Valgrind for example).
Unfortunately, during runtime, I only get the following error message:
Segmentation Fault
And nothing else. My question is:
Why doesn't the program give more info about the error during runtime?
Ps: This is not a question on why segmentation fault errors happen: I understand why.
No you can't, because segfaults are not reported by your program, but by your operating system receiving a trap at the CPU level (which is kind of an exception). At this point, the CPU deems your program unrecoverable and tells the operating system to stop it. Your program cannot do anything but shutdown, because the CPU gave that order.

Stack overflow in c++ with vc++ 2010 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have met a stack overflow in a program compiled using vc++ 2010. I open a debugger and attached it to the process.
Then I force the program to continue after the stack overflow error, every time there would be an access violation error.
My question is: is the access violation error caused by the stack overflow?
Yes. In Windows, stack overflow is detected by having an unreadable page of memory past the end of the stack. The first fault in this page raises a stack overflow exception. The next one raises an access violation.
But, to get to the core of the problem: don't do that. Stack overflows are not recoverable. Once you've had a stack overflow, your program is in an indeterminate state and you should just let it die.

How can i lookup an address of the addresspace of a process? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
If i have an address from the address space of a process is there some way to lookup it's value?
I am debugging an application and can see that there is a comparison between a fixed number and the content of an address. I would be helpful if i knew this value of the address.
Best way would be to access it from Visual Studio.
When the process is running, pause the execution (breakpoints etc...), go to Debug -> Windows -> Memory -> Memory 1 and just paste the address. It will show the raw memory values in hexadecimal and ascii .
ps: There is Memory 1 to Memory 4 in VS2010. They aren't different from each other. It is just to facilitate monitoring several memory location at once.
Maybe this is what you mean:
How to know the address range when searching for a function by its signature?
GetModuleHandle() will return the base address of the process, so that's your starting range.

Segfault in gtkmm implementation of conway's game of life [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
As mentioned in the question, I have a segfault in the implementation of Conway's game of life in gtkmm that I am working on.
It can be found here: https://github.com/sakekasi/game-of-life
The backtrace of the error can be found here: https://gist.github.com/3505525
When I insert print statements in cells_get or create_updated grid, it starts printing, doesn't produce a segfault and goes on forever without doing anything.
create_updated_grid is accessing cells off the edge of the grid. It's calling things like cells_get(i+1,j).
You need to change your out-of-bounds checks in cells_get to >=, not >.