mirror of
https://github.com/NixOS/nix
synced 2025-07-06 17:31:47 +02:00
Casting function pointers seems to be almost always UB. See https://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type Fixed by doing the casting of `void*` to `std::string*` inside the function instead. Caught by UBSan.
15 lines
331 B
C++
15 lines
331 B
C++
#pragma once
|
|
#include <string>
|
|
|
|
namespace nix::testing {
|
|
|
|
void observe_string_cb(const char * start, unsigned int n, void * user_data);
|
|
|
|
inline void * observe_string_cb_data(std::string & out)
|
|
{
|
|
return (void *) &out;
|
|
};
|
|
|
|
#define OBSERVE_STRING(str) nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
|
|
|
|
}
|