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

randombit / botan / 16100769786

06 Jul 2025 02:16PM UTC coverage: 90.577% (+0.004%) from 90.573%
16100769786

push

github

web-flow
Merge pull request #4961 from randombit/jack/fix-clang-tidy-readability-implicit-bool-conversion

Fix some clang-tidy readability-implicit-bool-conversion warnings

99055 of 109360 relevant lines covered (90.58%)

12330806.47 hits per line

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

91.3
/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
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
}  // namespace
40

41
Dynamically_Loaded_Library::Dynamically_Loaded_Library(std::string_view library) : m_lib_name(library), m_lib(nullptr) {
76✔
42
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
43
   m_lib = ::dlopen(m_lib_name.c_str(), RTLD_LAZY);
76✔
44

45
   if(m_lib == nullptr) {
76✔
46
      raise_runtime_loader_exception(m_lib_name, ::dlerror());
1✔
47
   }
48

49
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
50
   m_lib = ::LoadLibraryA(m_lib_name.c_str());
51

52
   if(m_lib == nullptr) {
53
      raise_runtime_loader_exception(m_lib_name, "LoadLibrary failed");
54
   }
55
#endif
56

57
   if(m_lib == nullptr) {
75✔
58
      raise_runtime_loader_exception(m_lib_name, "Dynamic load not supported");
59
   }
60
}
76✔
61

62
Dynamically_Loaded_Library::~Dynamically_Loaded_Library() {
75✔
63
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
64
   ::dlclose(m_lib);
75✔
65
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
66
   ::FreeLibrary(reinterpret_cast<HMODULE>(m_lib));
67
#endif
68
}
75✔
69

70
void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) {
77✔
71
   void* addr = nullptr;
77✔
72

73
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
74
   addr = ::dlsym(m_lib, symbol.c_str());
77✔
75
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
76
   addr = reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(m_lib), symbol.c_str()));
77
#endif
78

79
   if(addr == nullptr) {
77✔
80
      throw Invalid_Argument(fmt("Failed to resolve symbol {} in {}", symbol, m_lib_name));
×
81
   }
82

83
   return addr;
77✔
84
}
85

86
}  // 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