gpt4 book ai didi

c - *** 检测到 glibc *** realloc() : invalid old size

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:51 25 4
gpt4 key购买 nike

realloc() 的问题。我得到* 检测到 glibc * realloc():无效的旧大小

void reallocatePtrTable(mmUctNode* nodeToReallocate){
int newSize = (nodeToReallocate->PtrTableCapacity)*INCREASE_FACTOR;
printf("(re)Allocating %p with %d bytes. ",nodeToReallocate->childPtrTable,sizeof(mmUctNode*)*newSize);
nodeToReallocate->childPtrTable=
(mmUctNode**)realloc(nodeToReallocate->childPtrTable,sizeof(mmUctNode*)*newSize);
printf(" Got %p\n",nodeToReallocate->childPtrTable);
if(!nodeToReallocate->childPtrTable){
puts("Re-allocation failed");
exit(-1);
}
}

我确定我没有重新分配空指针或错误指针。初始内存分配由 malloc() 完成

(re)Allocating 0x8801fc8 with 480 bytes.  Got 0x8807a98
(re)Allocating 0x8807a98 with 960 bytes. Got 0x880d2b8
(re)Allocating 0x880d2b8 with 1920 bytes. Got 0x8818290
(re)Allocating 0x8818290 with 3840 bytes. Got 0x882e310
(re)Allocating 0x882e310 with 7680 bytes. Got 0x885a410
(re)Allocating 0x885a410 with 15360 bytes. Got 0x88b9018
(re)Allocating 0x88b9018 with 30720 bytes. *** glibc detected *** /home/: realloc(): invalid old size: 0x088b9018 ***
Segmentation fault

最佳答案

您可能不小心覆盖了 mallocs 内部簿记数据,例如通过缓冲区溢出。通常这被称为“内存损坏”。

关于c - *** 检测到 glibc *** realloc() : invalid old size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8732128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com