@@ -281,6 +281,13 @@ int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
281
281
i = ksl_bsearch (ksl , blk , key , ksl -> compar );
282
282
283
283
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
+ }
284
291
ksl_insert_node (ksl , blk , i , key , data );
285
292
++ ksl -> n ;
286
293
if (it ) {
@@ -453,8 +460,8 @@ static int key_equal(nghttp3_ksl_compar compar, const nghttp3_ksl_key *lhs,
453
460
return !compar (lhs , rhs ) && !compar (rhs , lhs );
454
461
}
455
462
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 ) {
458
465
nghttp3_ksl_blk * blk = ksl -> head ;
459
466
nghttp3_ksl_node * node ;
460
467
size_t i ;
@@ -468,10 +475,20 @@ void nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
468
475
for (;;) {
469
476
i = ksl_bsearch (ksl , blk , key , ksl -> compar );
470
477
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
+ }
472
484
473
485
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
+ }
475
492
ksl_remove_node (ksl , blk , i );
476
493
-- ksl -> n ;
477
494
if (it ) {
@@ -481,7 +498,7 @@ void nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
481
498
nghttp3_ksl_it_init (it , ksl , blk , i );
482
499
}
483
500
}
484
- return ;
501
+ return 0 ;
485
502
}
486
503
487
504
node = nghttp3_ksl_nth_node (ksl , blk , i );
0 commit comments