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:
commit
22378ea093
1 changed files with 9 additions and 0 deletions
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue