From 99f6149d92929d75a35530b62cba1b84a51f93d7 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 15 Jun 2017 13:57:48 -0500 Subject: [PATCH] If the ranking algorithm returns an empty result instead of null, catch that rather than letting it potentially break the output. --- NetTally.Core/Output/TallyOutput.cs | 6 ++++++ .../Votes/Counting/RankVoteCounting/RIRVRankVoteCounter.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NetTally.Core/Output/TallyOutput.cs b/NetTally.Core/Output/TallyOutput.cs index 5a3a6ccb..78d3d105 100644 --- a/NetTally.Core/Output/TallyOutput.cs +++ b/NetTally.Core/Output/TallyOutput.cs @@ -215,6 +215,9 @@ private void AddCompactTask(KeyValuePair task) int num = 1; foreach (var entry in task.Value) { + if (entry.Option == null) + continue; + string debug = AdvancedOptions.Instance.DebugMode ? $" >>> {entry.Debug}" : string.Empty; sb.AppendLine($"[{num++}] {entry.Option}{debug}"); } @@ -233,6 +236,9 @@ private void AddCompleteTask(KeyValuePair task) int index = 0; foreach (var winner in task.Value) { + if (winner.Option == null) + continue; + sb.Append("[b]"); sb.Append(rankWinnerLabels[index++]); sb.Append(":[/b] "); diff --git a/NetTally.Core/Votes/Counting/RankVoteCounting/RIRVRankVoteCounter.cs b/NetTally.Core/Votes/Counting/RankVoteCounting/RIRVRankVoteCounter.cs index 795ddfb5..8334639d 100644 --- a/NetTally.Core/Votes/Counting/RankVoteCounting/RIRVRankVoteCounter.cs +++ b/NetTally.Core/Votes/Counting/RankVoteCounting/RIRVRankVoteCounter.cs @@ -47,7 +47,7 @@ protected override RankResults RankTask(GroupedVotesByTask task) { RankResult winner = GetWinningVote(voterRankings, rankedVotes); - if (winner == null) + if (winner == null || winner.Option == null) break; winningChoices.Add(winner);