我收到此错误,但找不到原因,这是一个项目,我无法在此处真正显示源代码,但我像这样分配内存:
if(!data_counter)
lab=(ptr)malloc(sizeof(item));
else
lab=(ptr)realloc(lab,sizeof(item)*(DC+1));
即使我的代码编译和运行完美,我也一直在 Valgrind 中获取此日志。
我感觉我重新分配了错误的内存。sizeof(item) 中的 item 也是一个具有 4 个字段的结构
==18449==
==18449== HEAP SUMMARY:
==18449== in use at exit: 352 bytes in 1 blocks
==18449== total heap usage: 15 allocs, 14 frees, 4,416 bytes allocated
==18449==
==18449== Searching for pointers to 1 not-freed blocks
==18449== Checked 69,180 bytes
==18449==
==18449== LEAK SUMMARY:
==18449== definitely lost: 0 bytes in 0 blocks
==18449== indirectly lost: 0 bytes in 0 blocks
==18449== possibly lost: 0 bytes in 0 blocks
==18449== still reachable: 352 bytes in 1 blocks
==18449== suppressed: 0 bytes in 0 blocks
==18449== Reachable blocks (those to which a pointer was found) are not shown.
==18449== To see them, rerun with: --leak-check=full --show-reachable=yes
==18449==
==18449== Use --track-origins=yes to see where uninitialised values come from
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
==18449==
==18449== 1 errors in context 1 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804B960: checkLabel (12.c:797)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 1 errors in context 2 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BC24: checkLabel (12.c:836)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 2 errors in context 3 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BE61: update_labl_adrr (12.c:883)
==18449== by 0x804C720: main (12.c:1014)
==18449==
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
任何帮助将不胜感激
如果您指的是Conditional jump or move depends on uninitialized value(s)
错误,则意味着您的条件包含未初始化的值。
这可以在一个条件while
,for
,if
或switch
语句。从 Valgrind 回溯,您可以看出checkLabel
and 中有一些流控制语句update_labl_adrr
,但由于我们看不到该代码,因此很难说其他任何内容。
使用递归结构(即链表、树等)时的一个常见错误是不将next
/child
指针初始化为 NULL。这通常会导致您发布的错误。但是,这完全是猜测,因为我们对您的代码一无所知。
没有办法提供任何进一步的帮助,至少,如果不知道里面写了什么checkLabel
和update_labl_addr
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句