检测到堆损坏,堆缓冲区结束后仍在写内存
因此,我正在做有关课程和其他作业的作业。一切都编译了,我得到了预期的输出,但是我一直遇到一个错误,说 “检测到的堆损坏..... CRT检测到了堆在堆缓冲区结束后写下内存。”
当我在此之后返回代码时,一行被绿色突出显示,并说“在写信给所有者时,缓冲区超支”
这是代码:
void bank::setOwner(const char* nameOwner)
{
if (owner != nullptr)
delete[] owner;
int i = 0;
while (nameOwner[i++] != '\0');
owner = new char[i];
while (i >= 0) {
owner[i--] = nameOwner[i];
}
}
So I am doing this assignment about classes and whatnot. Everything compiles and i get the expected output, but I keep getting an error that says
"HEAP CORRUPTION DETECTED..... CRT detected that the application wrote memory after the end of heap buffer."
When I go back into my code after this, one line is highlighted by green and says "Buffer overrun while writing to owner"
Here is the code:
void bank::setOwner(const char* nameOwner)
{
if (owner != nullptr)
delete[] owner;
int i = 0;
while (nameOwner[i++] != '\0');
owner = new char[i];
while (i >= 0) {
owner[i--] = nameOwner[i];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我介绍大 rubber ducky ducky 。
现在进行了介绍,您可以使用其无限智慧来帮助检测问题和越野车代码。对话可能会这样:
您:
rd:
you:
rd:
您:
Let me introduce to the great rubber ducky.
Now that introductions are made, you can use its infinite wisdom to help detect problems and buggy code. The conversation could go like this:
You:
RD:
You:
RD:
You: