LCOV - code coverage report
Current view: top level - src/util - byte_units.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 80.0 % 5 4
Test Date: 2025-01-19 05:08:01 Functions: 100.0 % 1 1
Branches: 50.0 % 4 2

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2025-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #ifndef BITCOIN_UTIL_BYTE_UNITS_H
       6                 :             : #define BITCOIN_UTIL_BYTE_UNITS_H
       7                 :             : 
       8                 :             : #include <util/overflow.h>
       9                 :             : 
      10                 :             : #include <stdexcept>
      11                 :             : 
      12                 :             : //! Overflow-safe conversion of MiB to bytes.
      13                 :           1 : constexpr size_t operator"" _MiB(unsigned long long mebibytes)
      14                 :             : {
      15                 :           1 :     auto bytes{CheckedLeftShift(mebibytes, 20)};
      16         [ +  - ]:           1 :     if (!bytes || *bytes > std::numeric_limits<size_t>::max()) {
      17         [ +  - ]:           1 :         throw std::overflow_error("MiB value too large for size_t byte conversion");
      18                 :             :     }
      19                 :           0 :     return *bytes;
      20                 :             : }
      21                 :             : 
      22                 :             : #endif // BITCOIN_UTIL_BYTE_UNITS_H
        

Generated by: LCOV version 2.0-1