LCOV - code coverage report
Current view: top level - src - uint256.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 30 30 100.0 %
Date: 2024-05-24 08:22:33 Functions: 6 8 75.0 %
Branches: 18 32 56.2 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2020 The Bitcoin Core developers
       3                 :            : // Distributed under the MIT software license, see the accompanying
       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :            : 
       6                 :            : #include <uint256.h>
       7                 :            : 
       8                 :            : #include <util/strencodings.h>
       9                 :            : 
      10                 :            : template <unsigned int BITS>
      11                 :    4098237 : std::string base_blob<BITS>::GetHex() const
      12                 :            : {
      13                 :    4098237 :     uint8_t m_data_rev[WIDTH];
      14   [ +  +  +  + ]:  135217441 :     for (int i = 0; i < WIDTH; ++i) {
      15                 :  131119204 :         m_data_rev[i] = m_data[WIDTH - 1 - i];
      16                 :  131119204 :     }
      17                 :    4098237 :     return HexStr(m_data_rev);
      18                 :    4098237 : }
      19                 :            : 
      20                 :            : template <unsigned int BITS>
      21                 :     112006 : void base_blob<BITS>::SetHex(const char* psz)
      22                 :            : {
      23                 :     112006 :     std::fill(m_data.begin(), m_data.end(), 0);
      24                 :            : 
      25                 :            :     // skip leading spaces
      26   [ #  #  +  + ]:     113746 :     while (IsSpace(*psz))
      27                 :       1740 :         psz++;
      28                 :            : 
      29                 :            :     // skip 0x
      30   [ #  #  #  #  :     112006 :     if (psz[0] == '0' && ToLower(psz[1]) == 'x')
             +  +  +  + ]
      31                 :      94531 :         psz += 2;
      32                 :            : 
      33                 :            :     // hex string to uint
      34                 :     112006 :     size_t digits = 0;
      35   [ #  #  +  + ]:   38238597 :     while (::HexDigit(psz[digits]) != -1)
      36                 :   38126591 :         digits++;
      37                 :     112006 :     unsigned char* p1 = m_data.data();
      38                 :     112006 :     unsigned char* pend = p1 + WIDTH;
      39   [ #  #  #  #  :    3693949 :     while (digits > 0 && p1 < pend) {
             +  +  +  + ]
      40                 :    3581943 :         *p1 = ::HexDigit(psz[--digits]);
      41   [ #  #  +  + ]:    3581943 :         if (digits > 0) {
      42                 :    3581936 :             *p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4);
      43                 :    3581936 :             p1++;
      44                 :    3581936 :         }
      45                 :            :     }
      46                 :     112006 : }
      47                 :            : 
      48                 :            : template <unsigned int BITS>
      49                 :       1033 : void base_blob<BITS>::SetHex(const std::string& str)
      50                 :            : {
      51                 :       1033 :     SetHex(str.c_str());
      52                 :       1033 : }
      53                 :            : 
      54                 :            : template <unsigned int BITS>
      55                 :    3961659 : std::string base_blob<BITS>::ToString() const
      56                 :            : {
      57                 :    3961659 :     return (GetHex());
      58                 :            : }
      59                 :            : 
      60                 :            : // Explicit instantiations for base_blob<160>
      61                 :            : template std::string base_blob<160>::GetHex() const;
      62                 :            : template std::string base_blob<160>::ToString() const;
      63                 :            : template void base_blob<160>::SetHex(const char*);
      64                 :            : template void base_blob<160>::SetHex(const std::string&);
      65                 :            : 
      66                 :            : // Explicit instantiations for base_blob<256>
      67                 :            : template std::string base_blob<256>::GetHex() const;
      68                 :            : template std::string base_blob<256>::ToString() const;
      69                 :            : template void base_blob<256>::SetHex(const char*);
      70                 :            : template void base_blob<256>::SetHex(const std::string&);
      71                 :            : 
      72                 :            : const uint256 uint256::ZERO(0);
      73                 :            : const uint256 uint256::ONE(1);

Generated by: LCOV version 1.16