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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

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

7
#include <botan/mem_ops.h>
8

9
#include <botan/internal/ct_utils.h>
10
#include <botan/internal/safeint.h>
11
#include <cstdlib>
12
#include <new>
13

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

18
namespace Botan {
19

20
BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size) {
146,314,790✔
21
   if(elems == 0 || elem_size == 0)
146,314,790✔
22
      return nullptr;
23

24
   // Some calloc implementations do not check for overflow (?!?)
25

26
   if(!BOTAN_CHECKED_MUL(elems, elem_size).has_value())
146,314,790✔
27
      throw std::bad_alloc();
×
28

29
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
30
   if(void* p = mlock_allocator::instance().allocate(elems, elem_size))
146,314,790✔
31
      return p;
32
#endif
33

34
#if defined(BOTAN_TARGET_OS_HAS_ALLOC_CONCEAL)
35
   void* ptr = ::calloc_conceal(elems, elem_size);
36
#else
37
   void* ptr = std::calloc(elems, elem_size);  // NOLINT(*-no-malloc)
69,074,712✔
38
#endif
39
   if(!ptr) [[unlikely]]
69,074,712✔
40
      throw std::bad_alloc();
×
41
   return ptr;
42
}
43

44
void deallocate_memory(void* p, size_t elems, size_t elem_size) {
146,314,308✔
45
   if(p == nullptr) [[unlikely]]
146,314,308✔
46
      return;
×
47

48
   secure_scrub_memory(p, elems * elem_size);
146,314,308✔
49

50
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
51
   if(mlock_allocator::instance().deallocate(p, elems, elem_size))
146,314,308✔
52
      return;
53
#endif
54

55
   std::free(p);  // NOLINT(*-no-malloc)
69,074,567✔
56
}
57

58
void initialize_allocator() {
457✔
59
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
60
   mlock_allocator::instance();
457✔
61
#endif
62
}
457✔
63

64
uint8_t ct_compare_u8(const uint8_t x[], const uint8_t y[], size_t len) {
132,098✔
65
   volatile uint8_t difference = 0;
132,098✔
66

67
   for(size_t i = 0; i != len; ++i)
3,368,382✔
68
      difference = difference | (x[i] ^ y[i]);
3,236,284✔
69

70
   return CT::Mask<uint8_t>::is_zero(difference).value();
132,098✔
71
}
72

73
}
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

© 2025 Coveralls, Inc