前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则​Pro.bounds:边界安全群组

C++核心准则​Pro.bounds:边界安全群组

作者头像
面向对象思考
发布2020-11-10 11:02:20
6000
发布2020-11-10 11:02:20
举报

Pro.bounds: Bounds safety profile

Pro.bounds:边界安全群组

This profile makes it easier to construct code that operates within the bounds of allocated blocks of memory. It does so by focusing on removing the primary sources of bounds violations: pointer arithmetic and array indexing. One of the core features of this profile is to restrict pointers to only refer to single objects, not arrays.

此规则群组使构建在分配的内存块范围内运行的代码更加容易。它通过专注于消除违背边界规则的主要来源来做到这一点:指针算术和数组索引。此规则群组的核心功能之一是将指针限制为仅引用单个对象,而不是数组。

We define bounds-safety to be the property that a program does not use an object to access memory outside of the range that was allocated for it. Bounds safety is intended to be complete only when combined with Type safety and Lifetime safety, which cover other unsafe operations that allow bounds violations.

我们将边界安全性定义为程序不通过对象访问为其分配的范围之外的内存的属性。仅当与类型安全性和生命周期安全性结合使用时,边界安全性才是完整的,后者包含允许违反边界的其他不安全操作。

Bounds safety profile summary:

边界安全群组概要:

Impact(影响)

Bounds safety implies that access to an object - notably arrays - does not access beyond the object's memory allocation. This eliminates a large class of insidious and hard-to-find errors, including the (in)famous "buffer overflow" errors. This closes security loopholes as well as a prominent source of memory corruption (when writing out of bounds). Even if an out-of-bounds access is "just a read", it can lead to invariant violations (when the accessed isn't of the assumed type) and "mysterious values."

边界安全性意味着对对象(尤其是数组)的访问不会超出对象的内存分配范围。这消除了许多隐患和难以发现的错误,包括(著名的)“缓冲区溢出”错误。这可以消除安全漏洞以及内存损坏的主要根源(超出限制时)。即使越界访问只是“读取”,它也可能导致违反不变量(当访问的类型不是假定的类型时)和“神秘的价值”。

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#probounds-bounds-safety-profile

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Pro.bounds: Bounds safety profile
  • Pro.bounds:边界安全群组
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档