Add a couple more setting data safety measures

Prevent null dereferencing if data is null, instead just make the
functions return and ignore the get/set requests.
This commit is contained in:
jp9000
2014-01-28 15:45:30 -07:00
parent 6c2242dea8
commit c6300d0956
5 changed files with 48 additions and 7 deletions

View File

@@ -123,6 +123,31 @@ EXPORT bool obs_data_item_getbool(obs_data_item_t item, bool def);
EXPORT obs_data_t obs_data_item_getobj(obs_data_item_t item);
EXPORT obs_data_array_t obs_data_item_getarray(obs_data_item_t item);
/* ------------------------------------------------------------------------- */
/* OBS-specific functions */
static inline obs_data_t obs_data_newref(obs_data_t data)
{
if (data)
obs_data_addref(data);
else
data = obs_data_create();
return data;
}
static inline void obs_data_replace(obs_data_t *current, obs_data_t replacement)
{
if (!current)
return;
if (*current != replacement) {
replacement = obs_data_newref(replacement);
obs_data_release(*current);
*current = replacement;
}
}
#ifdef __cplusplus
}
#endif