用户向我报告错误行
read(unit_chk) ((kpt_latt(i,nkp),i=1,3),nkp=1,num_kpts)
错误(类似于Why do I get a C malloc assertion failure?)
malloc.c:2365: sysmalloc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask)
== 0)' failed.
Abort
据我所知,错误只发生在一组特定的输入上。此外,当read()
更改为等效
((kpt_latt(i,nkp),i=1,3),nkp=1,(num_kpts-1)), &
kpt_latt(1,num_kpts),kpt_latt(2,num_kpts),kpt_latt(3,num_kpts)
错误消失。即使使用不同的编译器版本(IntelStudio 2013 SP1 composer_xe_2013_sp1.2.144
而不是IntelStudio 2015 composer_xe_2015.6.233
)进行编译,错误也会消失。 (这些都来自用户的报告 - 我还没有复制错误。)
当程序通过valgrind
运行时,会报告
valgrind: m_mallocfree.c:268 (mk_plain_bszB): Assertion 'bszB != 0' failed.
valgrind: This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata. If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away. Please try that before reporting this as a bug.
在此之前,有一些消息Conditional jump or move depends on uninitialised value(s)
,Use of uninitialised value of size 8
和Invalid read of size 8
;在上面引用的陈述中有一个Invalid write of size 1
。
正在读入的数组在以前只分配一行的正确大小:
allocate(kpt_latt(3,num_kpts))
read(unit_chk) ((kpt_latt(i,nkp),i=1,3),nkp=1,num_kpts)
编辑:用户报告了可能的解决方案。正在读取的数组kpt_latt
使用错误的数据类型声明,即integer
,而文件中的数据写为real
。这当然是错误的;但这是否真实导致失败的malloc()
断言?
精细打印:我们在讨论默认类integer
(4字节)和双精度实数(8字节)。 kpt_latt
中产生的伪造值未被注意到,因为程序实际上并未使用它们。我仍然没有自己重现错误,所以我必须依赖用户告诉我的内容。