fix(libutil): avoid dangling reference warning in Hash deserialization#14349
fix(libutil): avoid dangling reference warning in Hash deserialization#14349lovesegfault wants to merge 1 commit intoNixOS:masterfrom
Conversation
Changed the hashS variable from a reference to a copy to eliminate the -Wdangling-reference compiler warning.
|
Ah I would like to fix |
| auto & obj = getObject(json); | ||
| auto algo = parseHashAlgo(getString(valueAt(obj, "algorithm")), xpSettings); | ||
| auto format = parseHashFormat(getString(valueAt(obj, "format"))); | ||
| auto & hashS = getString(valueAt(obj, "hash")); |
There was a problem hiding this comment.
Here it's fine actually. The warning is a false-positive caused by the second argument being a temporary std::string that dies at the end of the full expression. I think this is an instance of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114220.
There was a problem hiding this comment.
I will try to avoid that by fixing valueAt though.
There was a problem hiding this comment.
We can annotate it with [[gnu::no_dangle]] to silence the warning and remove the overload that takes a json && to make it fool-proof.
|
What we should do instead is mark |
|
#14351 Here is the PR doing the thing I mentioned, which I think side-steps the issue completely, as well as making things more efficient. |
Motivation
Changed the hashS variable from a reference to a copy to eliminate the
-Wdangling-referencecompiler warning.Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.