fix tevent::operator<#824
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces tevent::operator<’s memcmp-based comparison (which can read padding bytes) with a field-by-field comparison to avoid undefined behavior when comparing otherwise-equal events.
Changes:
- Removed
#include <cstring>fromfield.cpp. - Reimplemented
tevent::operator<as a lexicographic comparison acrossteventmembers instead ofmemcmp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(trigger_card != v.trigger_card) return trigger_card < v.trigger_card; | ||
| if(event_cards != v.event_cards) return event_cards < v.event_cards; | ||
| if(reason_effect != v.reason_effect) return reason_effect < v.reason_effect; |
There was a problem hiding this comment.
operator< now compares raw pointers with <. In C++, relational comparison of unrelated pointers is unspecified and can violate the strict-weak-ordering requirement for std::set/std::map keys. Use std::less<card*>{}(trigger_card, v.trigger_card) (and similarly for group* / effect*) to get a well-defined total order; also consider custom comparators for other ordered containers that compare effect* directly (e.g., std::set<std::pair<effect*, tevent>>).
memcmp2 structs may compare padding bytes, in edge cases which 2 structs are same it will cause UB.