I have a native (C++) method in Android that makes the app "crash". The statement I want executed to cause the error and the application to close is the following:
uint32_t crash = (rand % 0xFFFFFFFF) / 0.0;
The curious thing is that when I compile to do the test this line is not executed (as I have verified debugging), the program skips it and does not execute it, I understand why it detects that it is a division by zero. Does anyone know how I can force it to run and cause it to crash?
Thank you very much.
A division by zero is not a crash, it is undefined behavior as can be seen in the C++ standard (translation and emphasis mine):
Faced with undefined behavior the compiler can decide to do whatever it sees fit, for example: it can decide to do nothing, it can decide to give a random value, it can decide not to compile that code, it can decide to throw an exception, or it can decide to invoke daemons in your nostrils .
If you want to force an error try executing a method of a nonexistent object: