From 893f106189198676d8afe82bab711a382eb75fcb Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 9 Sep 2016 11:53:37 -0700 Subject: [PATCH] Fix divide by zero error Fixes #5674 // FREEBIE --- .../securesms/util/SmsCharacterCalculator.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/util/SmsCharacterCalculator.java b/src/org/thoughtcrime/securesms/util/SmsCharacterCalculator.java index 844d44ac25..8b61f99e98 100644 --- a/src/org/thoughtcrime/securesms/util/SmsCharacterCalculator.java +++ b/src/org/thoughtcrime/securesms/util/SmsCharacterCalculator.java @@ -27,8 +27,15 @@ public class SmsCharacterCalculator extends CharacterCalculator { int messagesSpent = length[0]; int charactersSpent = length[1]; int charactersRemaining = length[2]; - int maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent; + int maxMessageSize; + + if (messagesSpent > 0) { + maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent; + } else { + maxMessageSize = (charactersSpent + charactersRemaining); + } + return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize); } }