cam: options: fix access to uninit variable
operator[] doesn't check if the option exists in the values_ map, so it can return a pointer to location outside the map. Fix by returning an empty OptionValue if the option is not found. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> [Kieran: Adjust s_empty naming to 'empty'] Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
committed by
Kieran Bingham
parent
265daf6e59
commit
8e6ca49687
@@ -61,7 +61,12 @@ bool OptionsBase<T>::isSet(const T &opt) const
|
||||
template<typename T>
|
||||
const OptionValue &OptionsBase<T>::operator[](const T &opt) const
|
||||
{
|
||||
return values_.find(opt)->second;
|
||||
static const OptionValue empty;
|
||||
|
||||
auto it = values_.find(opt);
|
||||
if (it != values_.end())
|
||||
return it->second;
|
||||
return empty;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user