From 655b6571bd4a26f91d877a3493b15a0016dbbe43 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 15 Jun 2021 16:50:09 -0500 Subject: [PATCH] fix(cli): Don't crash on races I misused `compare_exchange` when I didn't even really need it. Fixes #284 --- CHANGELOG.md | 4 ++++ src/bin/typos-cli/report.rs | 21 ++++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3800e15..a654706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +#### Bug Fixes + +- Fix a crash from hitting a race condition + ## [1.0.8] - 2021-06-15 ## [1.0.7] - 2021-06-15 diff --git a/src/bin/typos-cli/report.rs b/src/bin/typos-cli/report.rs index 82c1e67..0d20f2c 100644 --- a/src/bin/typos-cli/report.rs +++ b/src/bin/typos-cli/report.rs @@ -59,21 +59,12 @@ impl<'r> MessageStatus<'r> { impl<'r> Report for MessageStatus<'r> { fn report(&self, msg: Message) -> Result<(), std::io::Error> { - let _ = self.typos_found.compare_exchange( - false, - msg.is_correction(), - atomic::Ordering::Relaxed, - atomic::Ordering::Relaxed, - ); - let _ = self - .errors_found - .compare_exchange( - false, - msg.is_error(), - atomic::Ordering::Relaxed, - atomic::Ordering::Relaxed, - ) - .unwrap(); + if msg.is_correction() { + self.typos_found.store(true, atomic::Ordering::Relaxed); + } + if msg.is_error() { + self.errors_found.store(true, atomic::Ordering::Relaxed); + } self.reporter.report(msg) } }