程序异常终止

时间:2016-01-25 14:58:40

标签: c++ crash g++ g++4.9

我正在用C ++编写一个用于codeingame.com的机器人。我正在PC上编译我的程序。然后我将它发送到codeingame.com服务器执行。所以我无法在本地调试它。

我编写了一个用于排序数据的谓词。以下是相关的代码:

代码1

for (const auto &zz : zone_to_zone)
{
    vector<pair<int, int>> can_go;

    for (int to : zz.second)
        can_go.push_back({ to, visit_count[to] });

    sort(can_go.begin(), can_go.end(),
        [](const pair<int, int>& z1, const pair<int, int>& z2)
    {
        return z1.second < z2.second;
    });

此程序在执行上述排序次数后在服务器上崩溃,并出现以下错误:

Standard Error Stream:

Aborted.

at raise.c. function __GI_raise (sig=sig@entry=6) on line 56
at abort.c. function __GI_abort () on line 89
at libc_fatal.c. function __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff6b1bc60 "*** Error in `%s': %s: 0x%s ***\n") on line 175
at malloc.c. function malloc_printerr (action=1, str=0x7ffff6b17d1e "free(): invalid pointer", ptr=<optimized out>) on line 4996
at malloc.c. function _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) on line 3840
at new_allocator.h. function __gnu_cxx::new_allocator<Zone>::deallocate ( this=0x7fffffffe8e0, __p=0x61e0f0) on line 110
at alloc_traits.h. function std::allocator_traits<std::allocator<Zone> >::deallocate (__a=..., __p=0x61e0f0, __n=32) on line 383
at stl_vector.h. function std::_Vector_base<Zone, std::allocator<Zone> >::_M_deallocate (this=0x7fffffffe8e0, __p=0x61e0f0, __n=32) on line 178
at stl_vector.h. function std::_Vector_base<Zone, std::allocator<Zone> >::~_Vector_base (this=0x7fffffffe8e0, __in_chrg=<optimized out>) on line 160
at stl_vector.h. function std::vector<Zone, std::allocator<Zone> >::~vector ( this=0x7fffffffe8e0, __in_chrg=<optimized out>) on line 425

如果我稍微更改谓词:

代码2

for (const auto &zz : zone_to_zone)
{
    vector<pair<int, int>> can_go;

    for (int to : zz.second)
        can_go.push_back({ to, visit_count[to] });

    sort(can_go.begin(), can_go.end(),
        [](const pair<int, int>& z1, const pair<int, int>& z2)
    {
        return false;
    });

然后程序不会崩溃!

服务器正在使用g ++ 4.9。为什么会这样? Code 1有什么问题?

0 个答案:

没有答案