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

randombit / botan / 16249365818

13 Jul 2025 12:56PM UTC coverage: 90.618% (+0.002%) from 90.616%
16249365818

Pull #4985

github

web-flow
Merge 34acb0b10 into cf74a5db8
Pull Request #4985: Enable and fix clang-tidy warning cppcoreguidelines-prefer-member-initializer

99527 of 109831 relevant lines covered (90.62%)

12274327.89 hits per line

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

87.27
/src/lib/filters/filter.cpp
1
/*
2
* Filter
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/filter.h>
9

10
#include <botan/assert.h>
11
#include <botan/exceptn.h>
12

13
namespace Botan {
14

15
/*
16
* Filter Constructor
17
*/
18
Filter::Filter() {
136✔
19
   m_next.resize(1);
136✔
20
}
136✔
21

22
void Filter::send(std::span<const uint8_t> in, size_t length) {
89✔
23
   BOTAN_ASSERT_NOMSG(length <= in.size());
89✔
24
   send(in.data(), length);
89✔
25
}
89✔
26

27
/*
28
* Send data to all ports
29
*/
30
void Filter::send(const uint8_t input[], size_t length) {
183✔
31
   if(length == 0) {
183✔
32
      return;
33
   }
34

35
   bool nothing_attached = true;
36
   for(size_t j = 0; j != total_ports(); ++j) {
312✔
37
      if(m_next[j] != nullptr) {
157✔
38
         if(!m_write_queue.empty()) {
157✔
39
            m_next[j]->write(m_write_queue.data(), m_write_queue.size());
×
40
         }
41
         m_next[j]->write(input, length);
157✔
42
         nothing_attached = false;
157✔
43
      }
44
   }
45

46
   if(nothing_attached) {
155✔
47
      m_write_queue += std::make_pair(input, length);
×
48
   } else {
49
      m_write_queue.clear();
155✔
50
   }
51
}
52

53
/*
54
* Start a new message
55
*/
56
void Filter::new_msg() {
207✔
57
   start_msg();
207✔
58
   for(size_t j = 0; j != total_ports(); ++j) {
349✔
59
      if(m_next[j] != nullptr) {
142✔
60
         m_next[j]->new_msg();
142✔
61
      }
62
   }
63
}
207✔
64

65
/*
66
* End the current message
67
*/
68
void Filter::finish_msg() {
207✔
69
   end_msg();
207✔
70
   for(size_t j = 0; j != total_ports(); ++j) {
349✔
71
      if(m_next[j] != nullptr) {
142✔
72
         m_next[j]->finish_msg();
142✔
73
      }
74
   }
75
}
207✔
76

77
/*
78
* Attach a filter to the current port
79
*/
80
void Filter::attach(Filter* new_filter) {
20✔
81
   if(new_filter != nullptr) {
20✔
82
      Filter* last = this;
83
      while(last->get_next() != nullptr) {
24✔
84
         last = last->get_next();
4✔
85
      }
86
      last->m_next[last->current_port()] = new_filter;
20✔
87
   }
88
}
20✔
89

90
/*
91
* Set the active port on a filter
92
*/
93
void Filter::set_port(size_t new_port) {
×
94
   if(new_port >= total_ports()) {
×
95
      throw Invalid_Argument("Filter: Invalid port number");
×
96
   }
97
   m_port_num = new_port;
×
98
}
×
99

100
/*
101
* Return the next Filter in the logical chain
102
*/
103
Filter* Filter::get_next() const {
28✔
104
   if(m_port_num < m_next.size()) {
28✔
105
      return m_next[m_port_num];
28✔
106
   }
107
   return nullptr;
108
}
109

110
/*
111
* Set the next Filters
112
*/
113
void Filter::set_next(Filter* filters[], size_t size) {
81✔
114
   m_next.clear();
81✔
115

116
   m_port_num = 0;
81✔
117
   m_filter_owns = 0;
81✔
118

119
   while(size > 0 && filters != nullptr && (filters[size - 1] == nullptr)) {
87✔
120
      --size;
6✔
121
   }
122

123
   if(filters != nullptr && size > 0) {
81✔
124
      m_next.assign(filters, filters + size);
4✔
125
   }
126
}
81✔
127

128
/*
129
* Return the total number of ports
130
*/
131
size_t Filter::total_ports() const {
9,033✔
132
   return m_next.size();
9,033✔
133
}
134

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