1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-01 06:31:00 +01:00

Merge pull request #13762 from xokdvium/delete-footguns

libutil: Delete footgun overloads of get and getOr
This commit is contained in:
Sergei Zimmerman 2025-08-15 17:58:32 +03:00 committed by GitHub
commit 22378ea093
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -214,6 +214,10 @@ typename T::mapped_type * get(T & map, const typename T::key_type & key)
return &i->second; 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. * 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; 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. * Remove and return the first item from a container.
*/ */