From d8972317fc4314864619cadd5620ae780da657a3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 13 Feb 2020 16:12:16 +0100 Subject: [PATCH] Prevent uninitialized StorePath creation --- src/libstore/path.hh | 2 ++ src/libutil/rust-ffi.hh | 2 ++ src/nix/why-depends.cc | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libstore/path.hh b/src/libstore/path.hh index c31ea2179..c90bb1fff 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -18,6 +18,8 @@ extern "C" { struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop> { + StorePath() = delete; + static StorePath make(std::string_view path, std::string_view storeDir); static StorePath make(unsigned char hash[20], std::string_view name); diff --git a/src/libutil/rust-ffi.hh b/src/libutil/rust-ffi.hh index 469a5fba3..228e2eead 100644 --- a/src/libutil/rust-ffi.hh +++ b/src/libutil/rust-ffi.hh @@ -113,6 +113,8 @@ extern "C" { struct String : Vec { + String() = delete; + String(std::string_view s) { ffi_String_new(StringSlice(s), this); diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 8566e5851..c24ae7c8e 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -103,7 +103,7 @@ struct CmdWhyDepends : SourceExprCommand std::map graph; for (auto & path : closure) - graph.emplace(path.clone(), Node{path.clone(), cloneStorePathSet(store->queryPathInfo(path)->references)}); + graph.emplace(path.clone(), Node { .path = path.clone(), .refs = cloneStorePathSet(store->queryPathInfo(path)->references) }); // Transpose the graph. for (auto & node : graph) @@ -112,7 +112,7 @@ struct CmdWhyDepends : SourceExprCommand /* Run Dijkstra's shortest path algorithm to get the distance of every path in the closure to 'dependency'. */ - graph[dependencyPath.clone()].dist = 0; + graph.emplace(dependencyPath.clone(), Node { .path = dependencyPath.clone(), .dist = 0 }); std::priority_queue queue;