Skip to content

Commit

Permalink
String value refactor
Browse files Browse the repository at this point in the history
Related to NixOS#9047
  • Loading branch information
jlesquembre committed Nov 28, 2023
1 parent 674b027 commit f8f5398
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libexpr/c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const char * nix_get_string(nix_c_context * context, const Value * value)
try {
auto & v = check_value_not_null(value);
assert(v.type() == nix::nString);
return v.string.s;
return v.c_str();
}
NIXC_CATCH_ERRS_NULL
}
Expand All @@ -183,7 +183,7 @@ 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;
return v.path().to_string().c_str();

This comment has been minimized.

Copy link
@yorickvP

yorickvP Dec 6, 2023

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.

v._path.path should work instead but may not be how Eelco intended it.
Long-term this function should be rewritten to copy some data into a user-allocated string.

}
NIXC_CATCH_ERRS_NULL
}
Expand Down

0 comments on commit f8f5398

Please sign in to comment.