Skip to content

Commit 89dbc33

Browse files
committed
crash when delete multiple keys in tree map with user compare function
1 parent e8127cb commit 89dbc33

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

jsrc/xdic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,8 @@ static INLINE UI8 jtdelslotso(DIC *dic,void *k,I n,J jt,UI lv,VIRT virt,B *zv){I
16591659
// loop over keys (reverse order). Find the key, building parent info; then delete the key and value
16601660
// Because we don't store parent info, we have to do each key separately, which requires keeping a write
16611661
// lock after the first key - so we go ahead and keep the write lock throughout.
1662+
k=(void *)((I)k+(n-1)*(kib>>32)); // pointer to key being compared
16621663
if(unlikely(!(nodeb&(DICFICF<<8))))biasforcomp // we compare, not copy, and we use the original addr for the delete
1663-
void *ki=(void *)((I)k+(n-1)*(kib>>32)); // pointer to key being compared
16641664
for(i=n-1;i>=0;--i){I nodex;
16651665
UI8 chirn; // both children
16661666
UI4 pdir[64]; I pi=0; // parent/direction history; next slot to fill
@@ -1672,7 +1672,7 @@ static INLINE UI8 jtdelslotso(DIC *dic,void *k,I n,J jt,UI lv,VIRT virt,B *zv){I
16721672
for(nodex=rootx;;){ // traverse the tree, searching for index k. Current node is nodex
16731673
chirn=*(UI8*)&hashtbl[nodex*(nodeb>>24)]; // fetch both children
16741674
pdir[pi++]=parent+=SGNTO0(comp); // stack parent/dir going into nodex
1675-
comp=keysne((UI4)kib,kbase+(kib>>32)*(nodex>>1),ki,nodeb&(DICFICF<<8),errexit); // compare node key vs k, so k > node is ~0
1675+
comp=keysne((UI4)kib,kbase+(kib>>32)*(nodex>>1),k,nodeb&(DICFICF<<8),errexit); // compare node key vs k, so k > node is ~0
16761676
if(comp==0)break; // found at node nodex. chirn have the children, parent the parent\dir (also in pdir[])
16771677
parent=nodex; // we will fetch again. remember the parent of the next fetch
16781678
nodex=(chirn>>(comp&nodeb&0xff))&_bzhi_u64(~(UI8)1,nodeb); // choose left/right based on comparison, mask out garb.
@@ -1785,8 +1785,8 @@ findel:; // here when balancing complete
17851785
// obsolete printf("findel\n");
17861786
// obsolete auditnode(jt,dic,*(UI4AV3(dic->bloc.hash))&_bzhi_u64(~(UI8)1,dic->bloc.hashelesiz<<LGBB),~0LL,1); // scaf
17871787
if(0){notfound: zv[i]=0;} // if key not found, so indicate in return
1788-
if(unlikely(!(nodeb&(DICFICF<<8))))unbiasforcomp
1789-
ki=(void *)((I)ki-(kib>>32)); // advance to next search key
1788+
// obsolete if(unlikely(!(nodeb&(DICFICF<<8))))unbiasforcomp
1789+
k=(void *)((I)k-(kib>>32)); // advance to next search key
17901790
// obsolete printf("looping for next key\n");
17911791
}
17921792
R lv|DICLMSKOKRET; // good return, holding lock

0 commit comments

Comments
 (0)