Apply suggestions from code review

This commit is contained in:
José Luis Lafuente 2023-12-06 15:54:23 +01:00 committed by José Luis Lafuente
parent 550af113c6
commit 46f5d0ee7b
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A

View file

@ -183,7 +183,14 @@ const char * nix_get_path_string(nix_c_context * context, const Value * value)
try { try {
auto & v = check_value_not_null(value); auto & v = check_value_not_null(value);
assert(v.type() == nix::nPath); 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 NIXC_CATCH_ERRS_NULL
} }