CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.27k stars 4.12k forks source link

Moving into an NPC results in UB #76092

Closed l29ah closed 2 weeks ago

l29ah commented 2 weeks ago

Describe the bug

(gdb) bt
#0  0x00007fb10e8c42dc in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007fb10e874346 in raise () from /lib64/libc.so.6
#2  0x00007fb10e85c8f7 in abort () from /lib64/libc.so.6
#3  0x00007fb10eadab8f in std::__glibcxx_assert_fail (file=file@entry=0x55966f538011 "/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/array", line=line@entry=202, 
    function=function@entry=0x55966f550360 "constexpr std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](size_type) [with _Tp = RGBTuple; long unsigned int _Nm = 16; reference = RGBTuple&; size_type = long unsigned int]", 
    condition=condition@entry=0x55966f5275db "__n < this->size()") at /var/tmp/portage/sys-devel/gcc-14.2.1_p20240817/work/gcc-14-20240817/libstdc++-v3/src/c++11/assert_fail.cc:41
#4  0x000055966e4d88e1 in std::array<RGBTuple, 16ul>::operator[] (this=0x55966fcdef40 <rgbPalette>, __n=237) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/array:200
#5  std::array<RGBTuple, 16ul>::operator[] (__n=237, this=0x55966fcdef40 <rgbPalette>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/array:200
#6  cataimgui::imvec4_from_color (color=...) at src/cata_imgui.cpp:51
#7  0x000055966e5b579b in nc_color::operator ImVec4 (this=this@entry=0x7fff6d0b6da0) at src/color.cpp:34
#8  0x000055966e4d95e4 in cataimgui::draw_colored_text (text="Swap positions", color=..., wrap_width=wrap_width@entry=0, is_selected=is_selected@entry=0x0, is_focused=is_focused@entry=0x0, is_hovered=is_hovered@entry=0x0)
    at src/cata_imgui.cpp:435
#9  0x000055966f3e0716 in uilist_impl::draw_controls (this=0x5596b27286b0) at src/ui.cpp:128
#10 0x000055966e4d8784 in cataimgui::window::draw (this=0x5596b27286b0) at src/cata_imgui.cpp:643
#11 cataimgui::window::draw (this=0x5596b27286b0) at src/cata_imgui.cpp:612
#12 0x000055966f3e58e8 in ui_adaptor::redraw_invalidated () at src/ui_manager.cpp:448
#13 0x000055966f3e5a2d in ui_adaptor::redraw () at src/ui_manager.cpp:353
#14 0x000055966f3e5a60 in ui_manager::redraw () at src/ui_manager.cpp:516
#15 0x000055966f3e1d09 in uilist::query (this=this@entry=0x7fff6d0b75f8, loop=loop@entry=true, timeout=timeout@entry=-1, allow_unfiltered_hotkeys=allow_unfiltered_hotkeys@entry=false) at src/ui.cpp:884
#16 0x000055966e8815b2 in game::npc_menu (this=0x559685303dd0, who=...) at src/game.cpp:5671
#17 0x000055966e442fb7 in avatar_action::move (you=..., m=..., d=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:199
#18 0x000055966e8db511 in avatar_action::move (d=<synthetic pointer>..., m=..., you=...) at src/avatar_action.h:38
#19 game::do_regular_action (this=this@entry=0x559685303dd0, act=@0x7fff6d0b8464: ACTION_MOVE_BACK, player_character=..., mouse_target=std::optional [no contained value]) at src/handle_action.cpp:2264
#20 0x000055966e8def22 in game::handle_action (this=0x559685303dd0) at src/handle_action.cpp:3175
#21 0x000055966e72a7bf in do_turn () at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:199
#22 0x000055966e1375de in main (argc=<optimized out>, argv=<optimized out>) at src/main.cpp:873

Attach save file

2024.08.21.zip

Steps to reproduce

Expected behavior

No UB.

Screenshots

No response

Versions and configuration

Additional context

No response

l29ah commented 2 weeks ago

Bisecting tells https://github.com/CleverRaven/Cataclysm-DDA/pull/74341 is the culprit. @db48x please fix it.

db48x commented 2 weeks ago

I can’t reproduce it. What other conditions are necessary?

l29ah commented 2 weeks ago

Those are all i'm aware. There's also a similar bug with achievements: https://github.com/CleverRaven/Cataclysm-DDA/issues/72973

l29ah commented 2 weeks ago

Did a little debugging. The array of colors is 16 items long (as apparently defined by static constexpr size_t COLOR_NAMES_COUNT = 16;), the requested color is {attribute_value = 18432, index = 72} that is parent.disabled_color (c_dark_gray). Hope that helps.

db48x commented 2 weeks ago

Oh, you’re not running a tiles build. Let me try again.

db48x commented 2 weeks ago

Ahem. I’m not the culprit; it was a mine laid down by prior developers that @katemonster33 stepped on :)

Not hard to fix though.

l29ah commented 2 weeks ago

Fixed as of 7c664e153aaaad0d8cd3cd457188e9eeb59d19f5