1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

libutil: Delete footgun overloads of get and getOr

To avoid mistakes like the one in cea85e79ee.
These overloads are just asking for trouble.
This commit is contained in:
Sergei Zimmerman 2025-08-15 17:29:17 +03:00
parent c736db5320
commit 408c09a120
No known key found for this signature in database

View file

@ -214,6 +214,10 @@ typename T::mapped_type * get(T & map, const typename T::key_type & key)
return &i->second;
}
/** Deleted because this is use-after-free liability. Just don't pass temporaries to this overload set. */
template<class T>
typename T::mapped_type * get(T && map, const typename T::key_type & key) = delete;
/**
* Get a value for the specified key from an associate container, or a default value if the key isn't present.
*/
@ -227,6 +231,11 @@ getOr(T & map, const typename T::key_type & key, const typename T::mapped_type &
return i->second;
}
/** Deleted because this is use-after-free liability. Just don't pass temporaries to this overload set. */
template<class T>
const typename T::mapped_type &
getOr(T && map, const typename T::key_type & key, const typename T::mapped_type & defaultValue) = delete;
/**
* Remove and return the first item from a container.
*/