非计算机专业,好奇为什么会出现“程序依赖bug运行”的情况?

Views :
Update time : 2025-06-27 15:25:13

举个例子。

比如在c/c++语言里,这个写法是非法的,bug: int* fun(int nums[], size_t len) { int sth; char c1; float other; char c2; int tmpNum[len]; char str[len]; //do sth return tmpNum; }其中的tmpNum叫局部变量,它分配在栈上;当fun执行了return时,这块内存就被自动收回了,就不能再读写了。

但如果你不懂,你就是把tmpNum返回了;那么下游的使用者还真就能读到里面的值——内存是被收回了,但数据仍然在内存条上…。

非计算机专业,好奇为什么会出现“程序依赖bug运行”的情况?
Related News
Read More >>
Blog Post With Youtube Video 现在工作中k8s是使用containerd还是docker来管理容器?
2025-06-22 04:20:09
现在工作中k8s是使用containerd还是docker来管理容器?...
Blog Post With Youtube Video 有哪些你不喜欢的游戏机制?
2025-06-22 05:10:10
有哪些你不喜欢的游戏机制?...
Blog Post With Youtube Video 小鹏G7发布,对标小米YU7有优势吗?
2025-06-22 05:20:10
小鹏G7发布,对标小米YU7有优势吗?...
Blog Post With Youtube Video Gemini Advanced 和 aistudio有什么区别?
2025-06-22 04:40:09
Gemini Advanced 和 aistudio有什么区别?...

Leave Your Message