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

Assertion failure in the trading dialog "!(__hi < __lo)" #75742

Closed l29ah closed 3 weeks ago

l29ah commented 1 month ago

Describe the bug

(gdb) bt
#0  0x00007fca416c42dc in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007fca41674346 in raise () from /lib64/libc.so.6
#2  0x00007fca4165c8f7 in abort () from /lib64/libc.so.6
#3  0x00007fca418dab8f in std::__glibcxx_assert_fail (file=file@entry=0x55aa67650887 "/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algo.h", line=line@entry=3669, 
    function=function@entry=0x55aa676c997b "constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&) [with _Tp = long unsigned int]", condition=condition@entry=0x55aa67650823 "!(__hi < __lo)")
    at /var/tmp/portage/sys-devel/gcc-14.2.0/work/gcc-14.2.0/libstdc++-v3/src/c++11/assert_fail.cc:41
#4  0x000055aa66aa3d1d in std::clamp<unsigned long> (__val=@0x7ffe2f1a41e8: 0, __lo=@0x7ffe2f1a41f0: 3, __hi=<synthetic pointer>: <optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algo.h:3667
#5  std::clamp<unsigned long> (__hi=<synthetic pointer>: <optimized out>, __lo=@0x7ffe2f1a41f0: 3, __val=@0x7ffe2f1a41e8: 0) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algo.h:3667
#6  inventory_multiselector::on_input (this=0x55aac3621cc0, input=...) at src/inventory_ui.cpp:3939
#7  0x000055aa66aa470b in trade_selector::execute (this=0x55aac3621cc0) at src/inventory_ui.cpp:4565
#8  0x000055aa674b117c in trade_ui::perform_trade (this=this@entry=0x55aac7cb8a30) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:199
#9  0x000055aa6710ea59 in npc_trading::trade (np=..., cost=cost@entry=0, deal="Trade") at src/npctrade.cpp:286
#10 0x000055aa671033a9 in talk_function::start_trade (p=...) at src/npctalk_funcs.cpp:243
#11 0x000055aa670af0e6 in talk_effect_t::apply (this=0x7ffe2f1a4f28, d=...) at src/npctalk.cpp:6483
#12 0x000055aa670e6aea in dialogue::opt (this=this@entry=0x7ffe2f1a5208, d_win=..., topic=...) at src/npctalk.cpp:2696
#13 0x000055aa670e7085 in avatar::talk_to (this=this@entry=0x55aa8e817180, talk_with=std::unique_ptr<talker> = {...}, radio_contact=radio_contact@entry=false, is_computer=is_computer@entry=false, 
    is_not_conversation=is_not_conversation@entry=false) at src/npctalk.cpp:1401
#14 0x000055aa66a19423 in iexamine::intercom (you=..., examp=...) at src/iexamine.cpp:1490
#15 0x000055aa6699e3cd in game::examine (this=this@entry=0x55aa8e6045c0, examp=..., with_pickup=with_pickup@entry=false) at src/game.cpp:5932
#16 0x000055aa6699e828 in game::examine (this=this@entry=0x55aa8e6045c0, examp=..., with_pickup=with_pickup@entry=false) at src/game.cpp:5853
#17 0x000055aa6699eb58 in game::examine (this=this@entry=0x55aa8e6045c0, with_pickup=with_pickup@entry=false) at src/game.cpp:5780
#18 0x000055aa669f6d09 in game::do_regular_action (this=this@entry=0x55aa8e6045c0, act=@0x7ffe2f1a5cb4: ACTION_EXAMINE, player_character=..., mouse_target=std::optional [no contained value]) at src/handle_action.cpp:2390
#19 0x000055aa669fa022 in game::handle_action (this=0x55aa8e6045c0) at src/handle_action.cpp:3174
#20 0x000055aa66846507 in do_turn () at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:199
#21 0x000055aa6622186c in main (argc=<optimized out>, argv=<optimized out>) at src/main.cpp:873

Attach save file

N/A

Steps to reproduce

Expected behavior

No failures.

Screenshots

No response

Versions and configuration

Additional context

No response

l29ah commented 1 month ago

A more concrete repro:

PS File size too big: 25 MB are allowed, 46 MB were attempted to upload.

l29ah commented 1 month ago

Apparently this code was never tested, and the developer didn't use assertions, since the value being clamped is being fed instead of the lower bound.