Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94544dff authored by Chris Manton's avatar Chris Manton
Browse files

gd::fuzz: Replace InvokeIfNotEmpty with Empty check and Invoke

Bug: 331465718
Test: m .
Flag: EXEMPT, Mechanical Refactor
Change-Id: I9db07778d77a60f5a15ff79c1c9ded49eeb55d8c
parent 0acf60cc
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include <cstdint>
#include <vector>

#include "os/handler.h"
#include "common/contextual_callback.h"

namespace bluetooth {
namespace fuzz {
@@ -43,7 +43,9 @@ void InvokeIfValid(common::ContextualOnceCallback<void(TView)> callback, std::ve
  if (!packet.IsValid()) {
    return;
  }
  callback.InvokeIfNotEmpty(packet);
  if (!callback.IsEmpty()) {
    callback.Invoke(packet);
  }
}

template <typename TView>
@@ -52,7 +54,9 @@ void InvokeIfValid(common::ContextualCallback<void(TView)> callback, std::vector
  if (!packet.IsValid()) {
    return;
  }
  callback.InvokeIfNotEmpty(packet);
  if (!callback.IsEmpty()) {
    callback.Invoke(packet);
  }
}

}  // namespace fuzz
+10 −4
Original line number Diff line number Diff line
@@ -181,18 +181,24 @@ void FuzzHciLayer::injectAclEvent(std::vector<uint8_t> data) {
}

void FuzzHciLayer::injectAclDisconnect(FuzzedDataProvider& fdp) {
  acl_on_disconnect_.InvokeIfNotEmpty(fdp.ConsumeIntegral<uint16_t>(),
  if (!acl_on_disconnect_.IsEmpty()) {
    acl_on_disconnect_.Invoke(
        fdp.ConsumeIntegral<uint16_t>(),
        static_cast<hci::ErrorCode>(fdp.ConsumeIntegral<uint8_t>()));
  }
}

void FuzzHciLayer::injectLeAclEvent(std::vector<uint8_t> data) {
  InvokeIfValid<LeMetaEventView>(le_acl_event_handler_, data);
}

void FuzzHciLayer::injectLeAclDisconnect(FuzzedDataProvider& fdp) {
  le_acl_on_disconnect_.InvokeIfNotEmpty(fdp.ConsumeIntegral<uint16_t>(),
  if (!le_acl_on_disconnect_.IsEmpty()) {
    le_acl_on_disconnect_.Invoke(
        fdp.ConsumeIntegral<uint16_t>(),
        static_cast<hci::ErrorCode>(fdp.ConsumeIntegral<uint8_t>()));
  }
}

void FuzzHciLayer::injectLeAdvertisingEvent(std::vector<uint8_t> data) {
  InvokeIfValid<LeMetaEventView>(le_advertising_event_handler_, data);