☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

修改字符串字面常量

C++-Undefined-Behavior-8
目录 › next › previous

示例:

*((char*)"oops") = 'O';   // Undefined behavior, may crash
cout << "oops";           // If it doesn't crash, this might output ‘Oops’

修改字面常量是一种逻辑错误。多数通用系统会在运行时保护常量数据,相关修改会造成崩溃,在没有这种保护机制的系统中,字符串常量可能会被修改,但也可能会影响到其他相同的字符串常量,因为相同的字符串常量可能共用相同的存储空间。

依据

ISO/IEC 14882:2003 2.13.4(2)-undefined ISO/IEC 14882:2011 2.14.5(12)-undefined

规则

ID_constStrToNonConstPtr
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.