我六毛你六毛咱俩一块二 2020-07-21 17:33 采纳率: 0%
浏览 139

valgrind中的memcheck无法检查出memcpy()相关函数中的dst和src指针重叠。

memcheck无法检查出memcpy()相关函数中的dst和src指针重叠。且没有提示非法指针。

测试代码:
#include
#include
int main(){
int a, b[1];
char* c = malloc(4);
char* d = malloc(4);
a = ( a == 0 ? b[0] : b[1] );
memcpy(c, c+1, 2); //内存地址重叠
d[4] = 1;
free(d);
return 0;
}

检测结果:
==5023== Conditional jump or move depends on uninitialised value(s)
==5023== at 0x1091C4: main (test1.c:7)
==5023==
==5023== Invalid write of size 1
==5023== at 0x1091EB: main (test1.c:9)
==5023== Address 0x4a50094 is 0 bytes after a block of size 4 alloc'd
==5023== at 0x483B7FB: malloc (vg_replace_malloc.c:307)
==5023== by 0x1091BB: main (test1.c:6)
==5023==
==5023==
==5023== HEAP SUMMARY:
==5023== in use at exit: 4 bytes in 1 blocks
==5023== total heap usage: 2 allocs, 1 frees, 8 bytes allocated
==5023==
==5023== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==5023== at 0x483B7FB: malloc (vg_replace_malloc.c:307)
==5023== by 0x1091AD: main (test1.c:5)
==5023==
==5023== LEAK SUMMARY:
==5023== definitely lost: 4 bytes in 1 blocks
==5023== indirectly lost: 0 bytes in 0 blocks
==5023== possibly lost: 0 bytes in 0 blocks
==5023== still reachable: 0 bytes in 0 blocks
==5023== suppressed: 0 bytes in 0 blocks
==5023==
==5023== Use --track-origins=yes to see where uninitialised values come from
==5023== For lists of detected and suppressed errors, rerun with: -s
==5023== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

并没有给出类似于
Source and destination overlap in memcpy(0x41fe02c, 0x41fe028, 5)
的提示。

多次测试后也无法解决,这种情况是突然发生的,我记得在第一次安装测试后能够检查这类问题,但是后来测试相同的代码就查不出来了。有没有大神知道啊

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-07-31 15:14
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle数据库查询语句问题
  • ¥15 有没有c++绘制算法的佬们吗救孩一下
  • ¥15 android 蓝牙闪退
  • ¥15 绝缘子污秽comsol仿真参数
  • ¥15 Fatal error in Process MEMORY
  • ¥15 labelme生成的json有乱码?
  • ¥30 arduino vector defined in discarded section `.text' of wiring.c.o (symbol from plugin)
  • ¥20 如何训练大模型在复杂因素组成的系统中求得最优解
  • ¥15 关于#r语言#的问题:在进行倾向性评分匹配时,使用“match it"包提示”错误于eval(family$initialize): y值必需满足0 <= y <= 1“请问在进行PSM时
  • ¥45 求17位带符号原码乘法器verilog代码