[vlc-devel] [PATCH] input/control: UpdateBookmarksOption: prevent exessive bookmark-options
Filip Roséen
filip at atch.se
Thu May 18 14:46:06 CEST 2017
If UpdateBookmarksOption is called more than once, where the generated
bookmark-variable string would be different, it will result in the
input_item_t having several entries for "bookmarks=".
This patch makes it so that we overwrite any existing entry if such is
available, instead of simply appending a new one.
fixes: #18338
--
In the future this could be simplified greatly by introducing a
function such as input_item_SetOption, that would overwrite any
existing option if the to-be-inserted string refers to the same key.
I will however save that for later since such function would benefit
from some refactoring in terms of option handling for input_item_t (as
well as making sure that implementations/bugs similar to this one
actually benefits from such function).
---
src/input/control.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/input/control.c b/src/input/control.c
index 2891c5d8d9..027271be1f 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -616,9 +616,26 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
if( psz_value != NULL )
{
- input_item_AddOption( priv->p_item, psz_value,
- VLC_INPUT_OPTION_UNIQUE );
- free( psz_value );
+ bool b_overwritten = false;
+
+ for( int i = 0; i < priv->p_item->i_options; ++i )
+ {
+ char** ppsz_option = &priv->p_item->ppsz_options[i];
+
+ if( strncmp( *ppsz_option, "bookmarks=", 10 ) == 0 )
+ {
+ free( *ppsz_option );
+ *ppsz_option = psz_value;
+ b_overwritten = true;
+ }
+ }
+
+ if( !b_overwritten )
+ {
+ input_item_AddOption( priv->p_item, psz_value,
+ VLC_INPUT_OPTION_UNIQUE );
+ free( psz_value );
+ }
}
input_SendEventBookmark( p_input );
}
--
2.12.2
More information about the vlc-devel
mailing list