gpt4 book ai didi

c++ - malloc_consolidate 中的 SIGABRT - __FUNCTION__ 是否有可能返回 NULL?

转载 作者:行者123 更新时间:2023-11-30 03:42:40 25 4
gpt4 key购买 nike

我正在使用以下代码在 ARM 上登录:

template <typename T>
MyClass& operator<<(T const& t)
{
try
{
m_buffer << t;
}
catch (...)
{
/* No exceptions */
}
return *this;
}

这样使用:

myClass <<__FUNCTION__<< " some string and int" << 5;

但是有一次,我遇到了这样的崩溃(来自数千次测试)。 __FUNCTION__ 是否有可能返回 NULL(在本例中函数名长度为 20)?

Program terminated with signal 6, Aborted.
#0 0x3695f46c in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
67 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt full
#0 0x3695f46c in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
pid = <value optimized out>
selftid = 1673
res = <value optimized out>
#1 0x36964d70 in *__GI_abort () at abort.c:92
act = {__sigaction_handler = {sa_handler = 0, sa_sigaction = 0}, sa_mask = {__val = {0 <repeats 32 times>}}, sa_flags = 0, sa_restorer = 0}
sigs = {__val = {32, 0 <repeats 31 times>}}
#2 0x369a3e4c in __malloc_assert (assertion=<value optimized out>, file=0x36a5f560 "malloc.c", line=<value optimized out>, function=<value optimized out>) at malloc.c:352
No locals.
#3 0x369a41c0 in malloc_consolidate (av=0x34781de0) at malloc.c:5345
fb = <value optimized out>
maxfb = 0x36a79288
p = 0x728818
nextp = 0x6ddec8
unsorted_bin = 0x36a7928c
first_unsorted = <value optimized out>
nextchunk = 0x728ac8
size = 688
nextsize = 880297072
prevsize = <value optimized out>
bck = <value optimized out>
fwd = 0xbec
__func__ = "malloc_consolidate"
#4 0x369a70d8 in _int_malloc (av=0x36a7925c, bytes=<value optimized out>) at malloc.c:4573
nb = <value optimized out>
idx = 1673
bin = <value optimized out>
victim = 0x36a78000
size = <value optimized out>
victim_index = <value optimized out>
remainder = <value optimized out>
remainder_size = <value optimized out>
block = <value optimized out>
bit = <value optimized out>
map = <value optimized out>
fwd = <value optimized out>
bck = <value optimized out>
errstr = <value optimized out>
__func__ = "_int_malloc"
#5 0x369a83d4 in _do_malloc (bytes=525) at malloc.c:4011
ar_ptr = 0x36a7925c
victim = <value optimized out>
__func__ = "_do_malloc"
#6 0x369aa0e8 in *__GI___libc_malloc (bytes=525) at malloc.c:3648
mem = <value optimized out>
#7 0x350b1f4c in operator new(unsigned int) () from /lib/libstdc++.so.6
No symbol table info available.
#8 0x3508f0e8 in std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) () from /lib/libstdc++.so.6
No symbol table info available.
#9 0x3508fa4c in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int) () from /lib/libstdc++.so.6
No symbol table info available.
#10 0x350905d0 in std::string::reserve(unsigned int) () from /lib/libstdc++.so.6
No symbol table info available.
#11 0x35089de4 in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::overflow(int) () from /lib/libstdc++.so.6
No symbol table info available.
#12 0x3508e648 in std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int) () from /lib/libstdc++.so.6
No symbol table info available.
#13 0x35087604 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) () from /lib/libstdc++.so.6
No symbol table info available.
#14 0x35087958 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) () from /lib/libstdc++.so.6
No symbol table info available.
#15 0x350e8974 in MyClass::operator<< <char [21]> (this=0x34782200, t=...) at ...

使用 valgrind 我看不到任何奇怪的东西。

LE:在中止期间打印以下消息:malloc.c:5345: malloc_consolidate: Assertion 'p->fd_nextsize->bk_nextsize == p' failed

最佳答案

GCC 文档明确指出 __FUNCTION__ 为您提供了您所在函数的朴素名称。唯一失败的方法是您不在函数中。

很可能你在其他地方有 UB,但正如现在流行的那样,你没有提供 MCVE因此,不可能有信心进一步帮助您。

关于c++ - malloc_consolidate 中的 SIGABRT - __FUNCTION__ 是否有可能返回 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36690591/

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