From 46f5d0ee7bb8ecc01dad3a80000ed11fd7c236d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Lafuente?= Date: Wed, 6 Dec 2023 15:54:23 +0100 Subject: [PATCH] Apply suggestions from code review --- src/libexpr/c/nix_api_value.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libexpr/c/nix_api_value.cc b/src/libexpr/c/nix_api_value.cc index d013d5333..b0fb960c6 100644 --- a/src/libexpr/c/nix_api_value.cc +++ b/src/libexpr/c/nix_api_value.cc @@ -183,7 +183,14 @@ const char * nix_get_path_string(nix_c_context * context, const Value * value) try { auto & v = check_value_not_null(value); assert(v.type() == nix::nPath); - return v.path().to_string().c_str(); + // NOTE (from @yorickvP) + // v._path.path should work but may not be how Eelco intended it. + // Long-term this function should be rewritten to copy some data into a + // user-allocated string. + // We could use v.path().to_string().c_str(), but I'm concerned this + // crashes. Looks like .path() allocates a CanonPath with a copy of the + // string, then it gets the underlying data from that. + return v._path.path; } NIXC_CATCH_ERRS_NULL }