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

Commit 934ef60b authored by Xuan Xing's avatar Xuan Xing Committed by Chris Manton
Browse files

Explicitly return a const reference in mocks

Avoid returning a copy of the data from the mocks by setting an explicit return type before returning the static variable.  Otherwise the address sanitizer will fail referencing a non-static member.

Bug: 187825293
Test: Manually build.
Change-Id: I71282f17df35b09738948398efe3caeaadf63533
parent c63f8cec
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -225,7 +225,9 @@ extern struct BTM_BleVerifySignature BTM_BleVerifySignature;
// Return: const Octet16&
struct BTM_GetDeviceDHK {
  static const Octet16 return_value;
  std::function<const Octet16&()> body{[]() { return return_value; }};
  std::function<const Octet16&()> body{
      // Explicit return type is needed otherwise it returns copy of object
      []() -> const Octet16& { return return_value; }};
  const Octet16& operator()() { return body(); };
};
extern struct BTM_GetDeviceDHK BTM_GetDeviceDHK;
@@ -235,7 +237,9 @@ extern struct BTM_GetDeviceDHK BTM_GetDeviceDHK;
// Return: const Octet16&
struct BTM_GetDeviceEncRoot {
  static const Octet16 return_value;
  std::function<const Octet16&()> body{[]() { return return_value; }};
  std::function<const Octet16&()> body{
      // Explicit return type is needed otherwise it returns copy of object
      []() -> const Octet16& { return return_value; }};
  const Octet16& operator()() { return body(); };
};
extern struct BTM_GetDeviceEncRoot BTM_GetDeviceEncRoot;
@@ -245,7 +249,9 @@ extern struct BTM_GetDeviceEncRoot BTM_GetDeviceEncRoot;
// Return: const Octet16&
struct BTM_GetDeviceIDRoot {
  static const Octet16 return_value;
  std::function<const Octet16&()> body{[]() { return return_value; }};
  std::function<const Octet16&()> body{
      // Explicit return type is needed otherwise it returns copy of object
      []() -> const Octet16& { return return_value; }};
  const Octet16& operator()() { return body(); };
};
extern struct BTM_GetDeviceIDRoot BTM_GetDeviceIDRoot;