使用g ++生成的C ++中的运行时数组边界检查 [英] Runtime array bounds checking in C++ built with g++

查看:143
本文介绍了使用g ++生成的C ++中的运行时数组边界检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用g++编译的C ++中,有什么方法可以进行数组边界检查吗?

Is there any way to do array bounds checking in C++ compiled using g++?

  • Valgrind的Memcheck无法检测到堆栈上分配的阵列上的溢出.

  • Valgrind's Memcheck can't detect overflows on arrays allocated on the stack.

-fbounds-checking 启用的 GCC扩展名为理想情况下,不应以任何方式修改源代码.不能使用std::vectorstd::tr1::arrayboost::array,因为代码库很大,而且这种转换是不可行的.

Ideally, the source code shouldn't be modified in any way. Using std::vector, std::tr1::array or boost::array is not an option because the codebase is large and such shift would be infeasible.

推荐答案

有一个名为

There is a Valgrind tool called SGCheck (formerly known as Ptrcheck) that does check stack array bounds overrun.

valgrind --tool=exp-sgcheck <program> <arguments>

该工具仍被标记为实验性工具,它带有几个局限性.其中之一是:

The tool is still labeled experimental and it comes with several limitations. One of them is:

平台:堆栈/全局检查在PowerPC,ARM上无法正常工作 或S390X平台,仅在X86和AMD64目标上.那是因为 堆栈和全局检查需要跟踪函数调用和退出 可靠,并且没有明显的方法可以在使用链接的ABI上做到这一点 注册功能返回.

Platforms: the stack/global checks won't work properly on PowerPC, ARM or S390X platforms, only on X86 and AMD64 targets. That's because the stack and global checking requires tracking function calls and exits reliably, and there's no obvious way to do it on ABIs that use a link register for function returns.

这篇关于使用g ++生成的C ++中的运行时数组边界检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆