Merge pull request #11122 from L-as/fix-ub

Fix ub
This commit is contained in:
John Ericson 2024-07-16 18:51:17 -04:00 committed by GitHub
commit 463256b9e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View file

@ -1569,7 +1569,7 @@ void DerivationGoal::waiteeDone(GoalPtr waitee, ExitCode result)
{ {
Goal::waiteeDone(waitee, result); Goal::waiteeDone(waitee, result);
if (!useDerivation) return; if (!useDerivation || !drv) return;
auto & fullDrv = *dynamic_cast<Derivation *>(drv.get()); auto & fullDrv = *dynamic_cast<Derivation *>(drv.get());
auto * dg = dynamic_cast<DerivationGoal *>(&*waitee); auto * dg = dynamic_cast<DerivationGoal *>(&*waitee);

View file

@ -2,9 +2,10 @@
namespace nix::testing { namespace nix::testing {
void observe_string_cb(const char * start, unsigned int n, std::string * user_data) void observe_string_cb(const char * start, unsigned int n, void * user_data)
{ {
*user_data = std::string(start); auto user_data_casted = reinterpret_cast<std::string *>(user_data);
*user_data_casted = std::string(start);
} }
} }

View file

@ -3,14 +3,13 @@
namespace nix::testing { namespace nix::testing {
void observe_string_cb(const char * start, unsigned int n, std::string * user_data); void observe_string_cb(const char * start, unsigned int n, void * user_data);
inline void * observe_string_cb_data(std::string & out) inline void * observe_string_cb_data(std::string & out)
{ {
return (void *) &out; return (void *) &out;
}; };
#define OBSERVE_STRING(str) \ #define OBSERVE_STRING(str) nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
(nix_get_string_callback) nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
} }