Can undefined behavior erase the hard drive?(未定义的行为可以擦除硬盘驱动器吗?)
问题描述
来自Scott Meyers 撰写的《Effective C++ 3rd edition》":
<块引用>为了强调未定义行为的结果是不可预测的,并且可能会非常不愉快,有经验的 C++ 程序员经常说具有未定义行为的程序会擦除您的硬盘驱动器.
在什么情况下会发生这种情况?
例如,访问和写入数组范围之外的位置是否会损坏不属于此 C++ 程序或线程的内存?
可以吗?当然.事实上发生在我身上.
我编写了删除临时目录的代码.这涉及创建一个 recursive delete
>
字段并不总是被填充.我们的文件系统代码愉快地执行了 recursive delete *.*
命令.
我的同事注意到桌面上的图标突然消失了.拿出两台机器.
From "Effective C++ 3rd edition by Scott Meyers":
To emphasize that the results of undefined behavior are not predictable and may be very unpleasant, experienced C++ programmers often say that programs with undefined behavior can erase your hard drive.
Under what circumstances can this happen?
For example, can accessing and writing to locations out of array range corrupt memory that doesn't belong to this C++ program or thread?
Can it? Sure. Happened to me, in fact.
I wrote code to delete a temporary directory. That involved creating a recursive delete <temp directory>*.*
command. Due to a bug, the <temp directory>
field wasn't always filled in. Our file system code happily executed the recursive delete *.*
command.
My colleagues noticed when the icons on their desktop suddenly disappeared. Took out two machines.
这篇关于未定义的行为可以擦除硬盘驱动器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:未定义的行为可以擦除硬盘驱动器吗?
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01