本文介绍了是不可能使一个C ++应用程序“崩溃证明”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

假设我们在C ++中有一个SDK接受一些二进制数据(如图片)并做某事。是不可能使这个SDK防撞?崩溃我主要意味着由于用户传递的无效输入(如异常短的垃圾数据),由于操作系统对内存访问冲突的强制终止。

Let's say we have an SDK in C++ that accepts some binary data (like a picture) and does something. Is it not possible to make this SDK "crash-proof"? By crash I primarily mean forceful termination by the OS upon memory access violation, due to invalid input passed by the user (like an abnormally short junk data).

我没有C ++的经验,但是当我使用Google搜索时,我发现几个手段听起来像一个解决方案(使用向量而不是数组,配置编译器执行自动边界检查等)。

I have no experience with C++, but when I googled, I found several means that sounded like a solution (use a vector instead of an array, configure the compiler so that automatic bounds check is performed, etc.).

当我向开发人员介绍这一点时,他说这还是不可能的..不是我不相信他,但如果是这样,处理这个?我认为JVM每次执行边界检查。如果是这样,为什么不能在C ++中手动做同样的事情?

When I presented this to the developer, he said it is still not possible.. Not that I don't believe him, but if so, how is language like Java handling this? I thought the JVM performs everytime a bounds check. If so, why can't one do the same thing in C++ manually?

UPDATE

我不是说应用程序不会终止。我的意思是它不应该突然终止没有发生什么的信息(我的意思是它会转储核心等,但是是不可能显示一条消息,如参数x是无效的等等。)

UPDATE
By "Crash proof" I don't mean that the application does not terminate. I mean it should not abruptly terminate without information of what happened (I mean it will dump core etc., but is it not possible to display a message like "Argument x was not valid" etc.?)

推荐答案

您可以在C ++中检查数组的边界,std :: vector在()自动执行此操作

You can check the bounds of an array in C++, the std::vector at() does this automatically

这不会使你的应用程序崩溃的证明,你仍然允许故意拍摄自己在脚,但没有什么在c ++强制你拉扳机

This doesn't make your app crash proof, you are still allowed to deliberately shoot yourself in the foot but nothing in c++ forces you to pull the trigger

这篇关于是不可能使一个C ++应用程序“崩溃证明”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:48