From 75b4cc13a0894ae8d06b78eb0aa7ed25340b61e2 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 5 Jun 2020 14:28:53 +0100 Subject: [PATCH] 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. --- Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp index 81367f12503..60676fc9b66 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;