Skip to content

Commit b51d75e

Browse files
committed
fuzz: simplify FuzzedSock::m_peek_data
`FuzzedSock::m_peek_data` need not be an optional of a vector. It can be just a vector whereas an empty vector denotes "no peek data".
1 parent 0b94fb8 commit b51d75e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/test/fuzz/util/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ ssize_t FuzzedSock::Recv(void* buf, size_t len, int flags) const
191191
}
192192
std::vector<uint8_t> random_bytes;
193193
bool pad_to_len_bytes{m_fuzzed_data_provider.ConsumeBool()};
194-
if (m_peek_data.has_value()) {
194+
if (!m_peek_data.empty()) {
195195
// `MSG_PEEK` was used in the preceding `Recv()` call, return `m_peek_data`.
196-
random_bytes = m_peek_data.value();
196+
random_bytes = m_peek_data;
197197
if ((flags & MSG_PEEK) == 0) {
198-
m_peek_data.reset();
198+
m_peek_data.clear();
199199
}
200200
pad_to_len_bytes = false;
201201
} else if ((flags & MSG_PEEK) != 0) {

src/test/fuzz/util/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FuzzedSock : public Sock
4343
* If `MSG_PEEK` is used, then our `Recv()` returns some random data as usual, but on the next
4444
* `Recv()` call we must return the same data, thus we remember it here.
4545
*/
46-
mutable std::optional<std::vector<uint8_t>> m_peek_data;
46+
mutable std::vector<uint8_t> m_peek_data;
4747

4848
/**
4949
* Whether to pretend that the socket is select(2)-able. This is randomly set in the

0 commit comments

Comments
 (0)