LCOV - code coverage report
Current view: top level - src - warnings.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 17 28 60.7 %
Date: 2023-10-05 15:40:34 Functions: 4 5 80.0 %
Branches: 9 32 28.1 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2022 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 <warnings.h>
       7                 :            : 
       8                 :            : #include <common/system.h>
       9                 :            : #include <sync.h>
      10                 :            : #include <util/string.h>
      11                 :            : #include <util/translation.h>
      12                 :            : 
      13                 :            : #include <vector>
      14                 :            : 
      15                 :            : static GlobalMutex g_warnings_mutex;
      16                 :        173 : static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
      17                 :            : static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
      18                 :            : 
      19                 :          2 : void SetMiscWarning(const bilingual_str& warning)
      20                 :            : {
      21                 :          2 :     LOCK(g_warnings_mutex);
      22         [ +  - ]:          2 :     g_misc_warnings = warning;
      23                 :          2 : }
      24                 :            : 
      25                 :          0 : void SetfLargeWorkInvalidChainFound(bool flag)
      26                 :            : {
      27                 :          0 :     LOCK(g_warnings_mutex);
      28                 :          0 :     fLargeWorkInvalidChainFound = flag;
      29                 :          0 : }
      30                 :            : 
      31                 :          3 : bilingual_str GetWarnings(bool verbose)
      32                 :            : {
      33                 :          3 :     bilingual_str warnings_concise;
      34                 :          3 :     std::vector<bilingual_str> warnings_verbose;
      35                 :            : 
      36   [ +  -  +  - ]:          3 :     LOCK(g_warnings_mutex);
      37                 :            : 
      38                 :            :     // Pre-release build warning
      39                 :            :     if (!CLIENT_VERSION_IS_RELEASE) {
      40         [ +  - ]:          3 :         warnings_concise = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
      41         [ +  - ]:          3 :         warnings_verbose.emplace_back(warnings_concise);
      42                 :            :     }
      43                 :            : 
      44                 :            :     // Misc warnings like out of disk space and clock is wrong
      45   [ +  -  -  + ]:          3 :     if (!g_misc_warnings.empty()) {
      46         [ #  # ]:          0 :         warnings_concise = g_misc_warnings;
      47         [ #  # ]:          0 :         warnings_verbose.emplace_back(warnings_concise);
      48                 :          0 :     }
      49                 :            : 
      50         [ -  + ]:          3 :     if (fLargeWorkInvalidChainFound) {
      51         [ #  # ]:          0 :         warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
      52         [ #  # ]:          0 :         warnings_verbose.emplace_back(warnings_concise);
      53                 :          0 :     }
      54                 :            : 
      55         [ -  + ]:          3 :     if (verbose) {
      56   [ #  #  #  #  :          0 :         return Join(warnings_verbose, Untranslated("<hr />"));
                   #  # ]
      57                 :            :     }
      58                 :            : 
      59                 :          3 :     return warnings_concise;
      60                 :          3 : }

Generated by: LCOV version 1.14