• 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

82.35
/src/lib/utils/allocator.cpp
1
/*
2
* (C) 2017,2023 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/allocator.h>
8

9
#include <botan/mem_ops.h>
10
#include <botan/internal/int_utils.h>
11
#include <botan/internal/target_info.h>
12
#include <cstdlib>
13
#include <new>
14

15
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
16
   #include <botan/internal/locking_allocator.h>
17
#endif
18

19
namespace Botan {
20

21
BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size) {
153,649,285✔
22
   if(elems == 0 || elem_size == 0) {
153,649,285✔
23
      return nullptr;
24
   }
25

26
   // Some calloc implementations do not check for overflow (?!?)
27
   if(!checked_mul(elems, elem_size).has_value()) {
307,298,570✔
28
      throw std::bad_alloc();
×
29
   }
30

31
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
32
   // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
33
   if(void* p = mlock_allocator::instance().allocate(elems, elem_size)) {
153,649,285✔
34
      return p;
35
   }
36
#endif
37

38
#if defined(BOTAN_TARGET_OS_HAS_ALLOC_CONCEAL)
39
   void* ptr = ::calloc_conceal(elems, elem_size);
40
#else
41
   // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
42
   void* ptr = std::calloc(elems, elem_size);  // NOLINT(*-no-malloc,*-owning-memory)
32,286,977✔
43
#endif
44
   if(ptr == nullptr) {
32,286,977✔
45
      [[unlikely]] throw std::bad_alloc();
×
46
   }
47
   return ptr;
48
}
49

50
void deallocate_memory(void* p, size_t elems, size_t elem_size) {
153,648,827✔
51
   if(p == nullptr) {
153,648,827✔
52
      [[unlikely]] return;
×
53
   }
54

55
   secure_scrub_memory(p, elems * elem_size);
153,648,827✔
56

57
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
58
   if(mlock_allocator::instance().deallocate(p, elems, elem_size)) {
153,648,827✔
59
      return;
60
   }
61
#endif
62

63
   std::free(p);  // NOLINT(*-no-malloc,*-owning-memory)
32,286,789✔
64
}
65

66
void initialize_allocator() {
407✔
67
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
68
   mlock_allocator::instance();
407✔
69
#endif
70
}
407✔
71

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