From 1d557f1b0e77d073d461a87c2ab28cbef4ead63c Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Sun, 3 May 2026 21:57:17 +0200 Subject: [PATCH] fix(code): replace GetHashCode comparison in ChatCode.Equals with field equality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Equals(object?) was delegating to GetHashCode() comparison, which is the textbook hash-collision anti-pattern: two distinct ChatCode values could in principle share a hash and be wrongly reported as equal. The current GetHashCode implementation packs Type/Source/Target into 24 bits and happens to be collision-free, but the contract is fragile — any future change to GetHashCode silently breaks Equals. Replaced with direct field-by-field comparison of Type, Source, Target. GetHashCode is left unchanged so dictionary/HashSet behavior stays identical. Pre-existing upstream issue (CodeRabbit critical finding); fixed in v1.0.0 standalone cut where we own the codebase. --- HellionChat/Code/ChatCode.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/HellionChat/Code/ChatCode.cs b/HellionChat/Code/ChatCode.cs index a6d14e9..32b717a 100755 --- a/HellionChat/Code/ChatCode.cs +++ b/HellionChat/Code/ChatCode.cs @@ -91,13 +91,10 @@ public class ChatCode public override bool Equals(object? obj) { - if (obj == null) - return false; - if (obj is not ChatCode code) return false; - return GetHashCode() == code.GetHashCode(); + return Type == code.Type && Source == code.Source && Target == code.Target; } public override int GetHashCode()