在 C++ 中,存在一个别名漏洞,它允许通过某些字符类型的指针读取或写入任何对象的对象表示。
这仅适用于char
和unsigned char
还是也适用于signed char
?
最佳答案
不,该规定不适用于signed char
。
[basic.lval]
8 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:
- [...]
- a
char
,unsigned char
, orstd::byte
type.
上面的引用包含与字符类型别名有关的最后一个项目符号。 signed char
被排除。
尽管如此,这也是主题的一部分 CWG Issue 350处理,因此可能会发生变化。考虑到问题所采取的方向,其目的是(最终,希望如此?)明确定义。
关于c++ - 别名漏洞是否适用于签名字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57653869/