From: teodor Date: Wed, 24 Dec 2008 15:53:04 +0000 (+0000) Subject: Fix several bugs in SFSFindDataFromSavedOrSave/SFSAddSaved interface X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=219d769a92db35047889d2ede526ae9dbd6eedb1;p=tedtools.git Fix several bugs in SFSFindDataFromSavedOrSave/SFSAddSaved interface --- diff --git a/sfxstr.c b/sfxstr.c index e9bc84a..6bf215d 100644 --- a/sfxstr.c +++ b/sfxstr.c @@ -155,7 +155,7 @@ SFSFindData(SFSTree *info, char *word, int len) { void* SFSFindDataOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *position) { if ( position ) - memset(position, 0, sizeof(position)); + memset(position, 0, sizeof(SFSTreePosition)); return SFSFindDataFromSavedOrSave(info, in, position); } @@ -185,11 +185,13 @@ SFSFindDataFromSavedOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *positi return NULL; else if ( STRNCMP(ptr, ((char*)node)+node->dataptr, node->nchar) ) { ptr+=node->nchar; - if ( ISEND(ptr, in->key, in->keylen) && node->isword) { - return (void*) ( ((char*)(node->data)) + ((node->haschild) ? sizeof(SFSNode*) : 0) ); + if ( ISEND(ptr, in->key, in->keylen) ) { + if (node->isword) + return (void*) ( ((char*)(node->data)) + ((node->haschild) ? sizeof(SFSNode*) : 0) ); + return NULL; } else if ( node->haschild ) { - node = getSkipChildPointer(info, node); pnode = (SFSNode**)( (char*)(node->data) ); + node = getSkipChildPointer(info, node); } else { return NULL; } @@ -202,11 +204,13 @@ SFSFindDataFromSavedOrSave(SFSTree *info, SFSDataIO *in, SFSTreePosition *positi StopMiddle = StopLow + ((StopHigh - StopLow) >> 1); if ( StopMiddle->val == *ptr ) { ptr++; - if ( ISEND(ptr, in->key, in->keylen) && StopMiddle->isword ) { - return (void*)( ((char*)node) + node->dataptr + info->datasize * StopMiddle->data ); + if ( ISEND(ptr, in->key, in->keylen) ) { + if ( StopMiddle->isword ) + return (void*)( ((char*)node) + node->dataptr + info->datasize * StopMiddle->data ); + return NULL; } else if ( StopMiddle->haschild ) { - node = getChildPointer(info, StopMiddle); pnode = (SFSNode**)(((char*)StopMiddle) + StopMiddle->child); + node = getChildPointer(info, StopMiddle); } else { return NULL; } @@ -228,7 +232,7 @@ void SFSAddSaved(SFSTree *info, SFSDataIO *in, SFSTreePosition *position) { CHECK_MEMORY(info); - if ( !(position->nodeptr && position->node) ) { + if ( !(position && position->nodeptr && position->node) ) { SFSAdd(info, in); return; }