奇怪的“总线错误” 在 string::string 构造函数中

发布于 2024-07-22 15:24:41 字数 259 浏览 1 评论 0原文

我一直在测试负责填充 multimap 对象的部分代码,这时开始弹出一个奇怪的错误:

int SetPortName(string ID, string Name)
    cout << "ID: " << ID << " Name: " << Name;
    ...
}

在 FreeBSD 5.4 中的非 root 用户下工作正常,但在 root 下运行时因“总线错误”而崩溃。

I've been testing part of my code responsible for filling multimap object, when a weird error started to pop up:

int SetPortName(string ID, string Name)
    cout << "ID: " << ID << " Name: " << Name;
    ...
}

works fine under non-root user in FreeBSD 5.4, but crashes with "Bus error" while ran under root.

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

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

发布评论

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

评论(1

初心 2024-07-29 15:24:41

标题提到了有关 string 构造函数的内容,但由于您没有显示任何调用构造函数的代码,因此我不得不假设问题实际上出在调用者中 > 该函数,其中将为参数构造两个 string 对象。 我的猜测是,您的两个实际参数之一是 char*,并且它是一个空指针。 使用调试器进一步调查。

The title mentions something about string's constructor, but since you don't show any code that calls a constructor, I'm forced to assume the problem is actually in the caller of this function, where two string objects would be constructed for the parameters. My guess is that one of your two actual parameters is a char*, and it's a null pointer. Use your debugger to investigate further.

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