@@ -281,6 +281,13 @@ int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
281281 i = ksl_bsearch (ksl , blk , key , ksl -> compar );
282282
283283 if (blk -> leaf ) {
284+ if (i < blk -> n &&
285+ !ksl -> compar (key , nghttp3_ksl_nth_node (ksl , blk , i )-> key )) {
286+ if (it ) {
287+ * it = nghttp3_ksl_end (ksl );
288+ }
289+ return NGHTTP3_ERR_INVALID_ARGUMENT ;
290+ }
284291 ksl_insert_node (ksl , blk , i , key , data );
285292 ++ ksl -> n ;
286293 if (it ) {
@@ -453,8 +460,8 @@ static int key_equal(nghttp3_ksl_compar compar, const nghttp3_ksl_key *lhs,
453460 return !compar (lhs , rhs ) && !compar (rhs , lhs );
454461}
455462
456- void nghttp3_ksl_remove (nghttp3_ksl * ksl , nghttp3_ksl_it * it ,
457- const nghttp3_ksl_key * key ) {
463+ int nghttp3_ksl_remove (nghttp3_ksl * ksl , nghttp3_ksl_it * it ,
464+ const nghttp3_ksl_key * key ) {
458465 nghttp3_ksl_blk * blk = ksl -> head ;
459466 nghttp3_ksl_node * node ;
460467 size_t i ;
@@ -468,10 +475,20 @@ void nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
468475 for (;;) {
469476 i = ksl_bsearch (ksl , blk , key , ksl -> compar );
470477
471- assert (i < blk -> n );
478+ if (i == blk -> n ) {
479+ if (it ) {
480+ * it = nghttp3_ksl_end (ksl );
481+ }
482+ return NGHTTP3_ERR_INVALID_ARGUMENT ;
483+ }
472484
473485 if (blk -> leaf ) {
474- assert (i < blk -> n );
486+ if (ksl -> compar (key , nghttp3_ksl_nth_node (ksl , blk , i )-> key )) {
487+ if (it ) {
488+ * it = nghttp3_ksl_end (ksl );
489+ }
490+ return NGHTTP3_ERR_INVALID_ARGUMENT ;
491+ }
475492 ksl_remove_node (ksl , blk , i );
476493 -- ksl -> n ;
477494 if (it ) {
@@ -481,7 +498,7 @@ void nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
481498 nghttp3_ksl_it_init (it , ksl , blk , i );
482499 }
483500 }
484- return ;
501+ return 0 ;
485502 }
486503
487504 node = nghttp3_ksl_nth_node (ksl , blk , i );
0 commit comments