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:
parent
c736db5320
commit
408c09a120
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;
|
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.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue