将从更改为到导致缓冲区溢出?

发布于 2024-12-10 11:49:16 字数 276 浏览 0 评论 0原文

我需要在我的办公室计算机上构建一些旧代码,该计算机安装了 gcc 4.4.5。我编辑了代码(删除 .h 或添加诸如 之类的内容),以使它们保持最新状态,以便可以通过 gcc 4.4.5 编译它们。然而,在看似成功的编译之后,每次运行二进制文件时都会出现缓冲区溢出。但代码在我家里的计算机上运行没有错误(gcc 4.1.2)。那么我所做的更改是否可能导致此错误?我不确定,因为我不是真正的程序员。

I need to build some old codes I got on my office computer, which has gcc 4.4.5 installed. I edited the code (deleting .h or adding things like <cstring>) in order to bring them up to date so they can be compiled by gcc 4.4.5. However, after a seemingly successful compile the binary file gives out buffer overflow every time I run it. But the code runs with no error on my computer at home (gcc 4.1.2). So is it possible the change I made caused this error? I am not sure since I am not really a programmer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-12-17 11:49:16

更有可能的是,原始代码在某些方面存在错误(未定义的行为、缓冲区溢出等),但旧编译器创建的(或旧库包含的)代码更能容忍这些问题(a)< /sup>。

恐怕您可能必须去解决(或找人解决)问题的根本原因。我问你的问题是:“如果你不认为自己是程序员,为什么要编辑代码并重建它?”。

我母亲也不是编码员,但她不会到处修补 Linux 内核 :-)


(a) 有时未定义的行为实际上有效!这实际上是它最烦人的方面。最好是它一直失败,这样我们就可以解决更多的问题,然后再将它们释放给我们可怜的客户。但是,即使它有效,这也不是一个好主意。

Far more likely is that the original code was buggy in some way (undefined behaviour, buffer overflows and so on) but the old compiler created (or the old library contained) code that was more tolerant of these issues (a).

I'm afraid you will probably have to go and fix (or get someone to fix) the root cause of the problem. My question to you would be: "if you don't consider yourself a programmer, why are you editing the code and rebuilding it?".

My mother's not a coder either but she doesn't go around tinkering in the Linux kernel :-)


(a) Sometimes undefined behaviour actually works! That's actually its most annoying aspect. Far better that it would fail all the time so that we'd fix more problems before unleashing them on our poor customers. But, even when it works, that doesn't make it a good idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文