• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 20160266155

12 Dec 2025 08:01AM UTC coverage: 90.357% (-0.001%) from 90.358%
20160266155

push

github

web-flow
Merge pull request #5172 from randombit/jack/fix-clang-tidy-misc-const-correctness

Fix and enable clang-tidy warning misc-const-correctness

100951 of 111725 relevant lines covered (90.36%)

12817908.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/lib/utils/dyn_load/dyn_load.cpp
1
/*
2
* Dynamically Loaded Object
3
* (C) 2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/dyn_load.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12
#include <botan/internal/target_info.h>
13
#include <sstream>
14

15
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
16
   #include <dlfcn.h>
17
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
18
   #define NOMINMAX 1
19
   #define _WINSOCKAPI_  // stop windows.h including winsock.h
20
   #include <windows.h>
21
#endif
22

23
namespace Botan {
24

25
namespace {
26

27
[[noreturn]] void raise_runtime_loader_exception(std::string_view lib_name, const char* msg) {
1✔
28
   std::ostringstream err;
1✔
29
   err << "Failed to load " << lib_name << ": ";
1✔
30
   if(msg != nullptr) {
1✔
31
      err << msg;
1✔
32
   } else {
33
      err << "Unknown error";
×
34
   }
35

36
   throw System_Error(err.str(), 0);
2✔
37
}
1✔
38

39
void* open_shared_library(const std::string& library) {
77✔
40
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
41
   void* lib = ::dlopen(library.c_str(), RTLD_LAZY);  // NOLINT(*-const-correctness)
77✔
42

43
   if(lib != nullptr) {
77✔
44
      return lib;
76✔
45
   } else {
46
      raise_runtime_loader_exception(library, ::dlerror());
1✔
47
   }
48

49
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
50
   void* lib = ::LoadLibraryA(library.c_str());  // NOLINT(*-const-correctness)
51

52
   if(lib != nullptr) {
53
      return lib;
54
   } else {
55
      raise_runtime_loader_exception(library, "LoadLibrary failed");
56
   }
57
#else
58
   raise_runtime_loader_exception(library, "Dynamic loading not supported");
59
#endif
60
}
61

62
}  // namespace
63

64
Dynamically_Loaded_Library::Dynamically_Loaded_Library(std::string_view library) :
77✔
65
      m_lib_name(library), m_lib(open_shared_library(m_lib_name)) {}
77✔
66

67
Dynamically_Loaded_Library::~Dynamically_Loaded_Library() {
76✔
68
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
69
   ::dlclose(m_lib);
76✔
70
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
71
   ::FreeLibrary(reinterpret_cast<HMODULE>(m_lib));
72
#endif
73
}
76✔
74

75
void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) const {
78✔
76
   // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
77
   if(void* addr = resolve_symbol_internal(symbol)) {
78✔
78
      return addr;
78✔
79
   }
80
   throw Invalid_Argument(fmt("Failed to resolve symbol {} in {}", symbol, m_lib_name));
×
81
}
82

83
void* Dynamically_Loaded_Library::resolve_symbol_internal(const std::string& symbol) const {
131✔
84
   // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
85
   void* addr = nullptr;
131✔
86
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
87
   addr = ::dlsym(m_lib, symbol.c_str());
131✔
88
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
89
   addr = reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(m_lib), symbol.c_str()));
90
#endif
91

92
   return addr;
131✔
93
}
94

95
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc