summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-06-05 14:28:53 +0100
committerAndreas Kling <kling@serenityos.org>2020-06-07 19:29:40 +0200
commit75b4cc13a0894ae8d06b78eb0aa7ed25340b61e2 (patch)
tree2b32806c4ee582cd259f16b03c339c23431d538d /Libraries
parent5b88aa8e96237f45a3adfd555086f3a72f283ae6 (diff)
downloadserenity-75b4cc13a0894ae8d06b78eb0aa7ed25340b61e2.zip
LibCrypto: Fix to_base10() for zero-value BigIntegers
All the magic is happening in a "while != 0" loop, so we ended up with an empty string for zero-value BigIntegers. Now we just check that upfront and return early.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp
index 81367f1250..60676fc9b6 100644
--- a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp
+++ b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp
@@ -80,6 +80,9 @@ UnsignedBigInteger UnsignedBigInteger::from_base10(const String& str)
String UnsignedBigInteger::to_base10() const
{
+ if (*this == UnsignedBigInteger { 0 })
+ return "0";
+
StringBuilder builder;
UnsignedBigInteger temp(*this);
UnsignedBigInteger quotient;