LCOV - code coverage report
Current view: top level - src - uint256.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 36 36 100.0 %
Date: 2021-06-29 14:35:33 Functions: 10 10 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 30 32 93.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                 :            : #include <string.h>
#      11                 :            : 
#      12                 :            : template <unsigned int BITS>
#      13                 :            : base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
#      14                 :    3233575 : {
#      15                 :    3233575 :     assert(vch.size() == sizeof(m_data));
#      16                 :    3233575 :     memcpy(m_data, vch.data(), sizeof(m_data));
#      17                 :    3233575 : }
#      18                 :            : 
#      19                 :            : template <unsigned int BITS>
#      20                 :            : std::string base_blob<BITS>::GetHex() const
#      21                 :    5714650 : {
#      22                 :    5714650 :     uint8_t m_data_rev[WIDTH];
#      23 [ +  + ][ +  + ]:  188563583 :     for (int i = 0; i < WIDTH; ++i) {
#      24                 :  182848933 :         m_data_rev[i] = m_data[WIDTH - 1 - i];
#      25                 :  182848933 :     }
#      26                 :    5714650 :     return HexStr(m_data_rev);
#      27                 :    5714650 : }
#      28                 :            : 
#      29                 :            : template <unsigned int BITS>
#      30                 :            : void base_blob<BITS>::SetHex(const char* psz)
#      31                 :     120740 : {
#      32                 :     120740 :     memset(m_data, 0, sizeof(m_data));
#      33                 :            : 
#      34                 :            :     // skip leading spaces
#      35 [ +  + ][ +  + ]:     120758 :     while (IsSpace(*psz))
#      36                 :         18 :         psz++;
#      37                 :            : 
#      38                 :            :     // skip 0x
#      39 [ +  + ][ +  + ]:     120740 :     if (psz[0] == '0' && ToLower(psz[1]) == 'x')
#         [ +  + ][ +  + ]
#      40                 :      76670 :         psz += 2;
#      41                 :            : 
#      42                 :            :     // hex string to uint
#      43                 :     120740 :     size_t digits = 0;
#      44 [ +  + ][ +  + ]:    7845654 :     while (::HexDigit(psz[digits]) != -1)
#      45                 :    7724914 :         digits++;
#      46                 :     120740 :     unsigned char* p1 = (unsigned char*)m_data;
#      47                 :     120740 :     unsigned char* pend = p1 + WIDTH;
#      48 [ +  + ][ +  + ]:    3983179 :     while (digits > 0 && p1 < pend) {
#         [ +  + ][ +  - ]
#      49                 :    3862439 :         *p1 = ::HexDigit(psz[--digits]);
#      50 [ +  - ][ +  + ]:    3862439 :         if (digits > 0) {
#      51                 :    3862427 :             *p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4);
#      52                 :    3862427 :             p1++;
#      53                 :    3862427 :         }
#      54                 :    3862439 :     }
#      55                 :     120740 : }
#      56                 :            : 
#      57                 :            : template <unsigned int BITS>
#      58                 :            : void base_blob<BITS>::SetHex(const std::string& str)
#      59                 :      22164 : {
#      60                 :      22164 :     SetHex(str.c_str());
#      61                 :      22164 : }
#      62                 :            : 
#      63                 :            : template <unsigned int BITS>
#      64                 :            : std::string base_blob<BITS>::ToString() const
#      65                 :    5545293 : {
#      66                 :    5545293 :     return (GetHex());
#      67                 :    5545293 : }
#      68                 :            : 
#      69                 :            : // Explicit instantiations for base_blob<160>
#      70                 :            : template base_blob<160>::base_blob(const std::vector<unsigned char>&);
#      71                 :            : template std::string base_blob<160>::GetHex() const;
#      72                 :            : template std::string base_blob<160>::ToString() const;
#      73                 :            : template void base_blob<160>::SetHex(const char*);
#      74                 :            : template void base_blob<160>::SetHex(const std::string&);
#      75                 :            : 
#      76                 :            : // Explicit instantiations for base_blob<256>
#      77                 :            : template base_blob<256>::base_blob(const std::vector<unsigned char>&);
#      78                 :            : template std::string base_blob<256>::GetHex() const;
#      79                 :            : template std::string base_blob<256>::ToString() const;
#      80                 :            : template void base_blob<256>::SetHex(const char*);
#      81                 :            : template void base_blob<256>::SetHex(const std::string&);
#      82                 :            : 
#      83                 :            : const uint256 uint256::ZERO(0);
#      84                 :            : const uint256 uint256::ONE(1);

Generated by: LCOV version 1.14