LCOV - code coverage report
Current view: top level - src - uint256.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 24 28 85.7 %
Date: 2023-11-10 23:46:46 Functions: 3 8 37.5 %
Branches: 14 32 43.8 %

           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                 :       1015 : std::string base_blob<BITS>::GetHex() const
      12                 :            : {
      13                 :            :     uint8_t m_data_rev[WIDTH];
      14 [ #  # ][ +  + ]:      33495 :     for (int i = 0; i < WIDTH; ++i) {
      15                 :      32480 :         m_data_rev[i] = m_data[WIDTH - 1 - i];
      16                 :      32480 :     }
      17                 :       1015 :     return HexStr(m_data_rev);
      18                 :            : }
      19                 :            : 
      20                 :            : template <unsigned int BITS>
      21                 :         54 : void base_blob<BITS>::SetHex(const char* psz)
      22                 :            : {
      23                 :         54 :     std::fill(m_data.begin(), m_data.end(), 0);
      24                 :            : 
      25                 :            :     // skip leading spaces
      26 [ #  # ][ -  + ]:         54 :     while (IsSpace(*psz))
      27                 :          0 :         psz++;
      28                 :            : 
      29                 :            :     // skip 0x
      30 [ #  # ][ #  # ]:         54 :     if (psz[0] == '0' && ToLower(psz[1]) == 'x')
         [ +  + ][ +  + ]
      31                 :         46 :         psz += 2;
      32                 :            : 
      33                 :            :     // hex string to uint
      34                 :         54 :     size_t digits = 0;
      35 [ #  # ][ +  + ]:       3510 :     while (::HexDigit(psz[digits]) != -1)
      36                 :       3456 :         digits++;
      37                 :         54 :     unsigned char* p1 = m_data.data();
      38                 :         54 :     unsigned char* pend = p1 + WIDTH;
      39 [ #  # ][ #  # ]:       1782 :     while (digits > 0 && p1 < pend) {
         [ +  + ][ +  + ]
      40                 :       1728 :         *p1 = ::HexDigit(psz[--digits]);
      41 [ #  # ][ -  + ]:       1728 :         if (digits > 0) {
      42                 :       1728 :             *p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4);
      43                 :       1728 :             p1++;
      44                 :       1728 :         }
      45                 :            :     }
      46                 :         54 : }
      47                 :            : 
      48                 :            : template <unsigned int BITS>
      49                 :          0 : void base_blob<BITS>::SetHex(const std::string& str)
      50                 :            : {
      51                 :          0 :     SetHex(str.c_str());
      52                 :          0 : }
      53                 :            : 
      54                 :            : template <unsigned int BITS>
      55                 :       1007 : std::string base_blob<BITS>::ToString() const
      56                 :            : {
      57                 :       1007 :     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.14