瀏覽代碼

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.
Linus Groh 5 年之前
父節點
當前提交
75b4cc13a0
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp

+ 3 - 0
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;