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

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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀