Is it impossible to make a C ++ application "Crash Proof"?

Let's say we have an SDK in C ++ that takes some binary data (like an image) and does something. Is it not possible to make this SDK "crash"? As a result of the accident, I primarily mean the forced termination of the OS in case of violation of access to memory due to invalid input transmitted by the user (for example, abnormally short unwanted data).

I have no experience with C ++, but when I googled, I found several ways that sounded like a solution (use a vector instead of an array, configure the compiler to do an automatic border check, etc.).

When I introduced this to the developer, he said it was still not possible. Not that I don't believe him, but if so, how does this language, like Java, handle this? I thought the JVM performs border checks every time. If so, why can't you do the same thing in C ++ manually?

UPDATE
By "Crash proof" I do not mean that the application does not end. I mean that it should not suddenly stop without information about what happened (I mean that it will unload the kernel, etc., but it does not seem possible to display a message like "Argument x is invalid" and etc.?)

+6
source share
8 answers

C++, std::vector::at .

, , C++ .

+6

. . -, , , , , . . , , , , , stack .

+4

- , (, ).

, . , .

, ... , , , .

- . .

, , , .

+4

, -

, "".

, - . - ( , - ). , , , . , , .

, ++, , - , , . [*] , , . .

, , , , , :

char *image_data = malloc(1);
free(image_data);
image_processing_function(image_data);

, "", , , . , , , .

Java , - Java, , , . , , "undefined " ++ , - Java (, ).

[*] : "".

+3

, , ++ .

Java, #, , .

++ . Exception Handling, , .

, ++ , .

+1

, ++ API crash-proof, , , . ( ) :

  • , .
  • Fuzz
  • unit test
+1

"crash proof" , , , , . , , / - , . , SDK, , , , . CrtDbg API.On Linux backtrace API - doc show_stackframe(). , . , , , , , , . , , . , , , , .

0
source

Actually, using border checks makes your application more likely to crash!

This is a good design because it means that if your program works, it is much more likely to work / correctly / rather than working incorrectly.

However, this application cannot be made “crash proof”, strictly speaking, until the stopping problem is resolved. Good luck

-1
source

All Articles