#define SFSTREE_VERSION 0x0100
-typedef unsigned long Opaque; /* XXX sizeof(Opaque) == sizeof(void *) */
+typedef uintptr_t Opaque; /* XXX sizeof(Opaque) == sizeof(void *) */
#define CHECK_MEMORY(tree) ( ( (tree)->plainmemory ) ? \
tlog(TL_CRIT|TL_EXIT, "Tree in plain memory - read only access") : (void)0 )
return info;
}
+#define ISEND(p,w,l) ( (l>0) ? ( ((char*)(p))-(w) >= (l) ) : ( *(p) == '\0' ) )
+
void*
-SFSFindData(SFSTree *info, char *word) {
+SFSFindData(SFSTree *info, char *word, int len) {
SFSNode *node = info->node;
SFSNodeData *StopLow, *StopHigh, *StopMiddle;
u_int8_t *ptr =(u_int8_t*)word;
- while( node && *ptr ) {
+ while( node && !ISEND(ptr, word, len) ) {
if ( node->isskip ) {
- if ( STRNCMP(ptr, ((char*)node)+node->dataptr, node->nchar) ) {
+ /*
+ if ( len>0 && len - (((char*)ptr) - word) > node->nchar )
+ return NULL;
+ else */ if ( STRNCMP(ptr, ((char*)node)+node->dataptr, node->nchar) ) {
ptr+=node->nchar;
- if ( *ptr=='\0' && node->isword) {
+ if ( ISEND(ptr, word, len) && node->isword) {
return (void*) ( ((char*)(node->data)) + ((node->haschild) ? sizeof(SFSNode*) : 0) );
} else if ( node->haschild ) {
node = getSkipChildPointer(info, node);
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
if ( StopMiddle->val == *ptr ) {
ptr++;
- if ( *ptr=='\0' && StopMiddle->isword ) {
+ if ( ISEND(ptr, word, len) && StopMiddle->isword ) {
return (void*)( ((char*)node) + node->dataptr + info->datasize * StopMiddle->data );
} else if ( StopMiddle->haschild ) {
node = getChildPointer(info, StopMiddle);