Skip to content

Commit

Permalink
fixed very long digit strings in query ( #762 )
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.sphinxsearch.com/sphinx/trunk@2847 406a0c4d-033a-0410-8de8-e80135713968
  • Loading branch information
kevg committed Jun 8, 2011
1 parent b17d3ba commit 92f722b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/sphinxquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,18 @@ int XQParser_t::GetToken ( YYSTYPE * lvalp )
const char * sToken = p;
while ( p<sEnd && isdigit ( *(BYTE*)p ) ) p++;

if ( p>sToken && ( *p=='\0' || isspace ( *(BYTE*)p ) || IsSpecial(*p) ) )
static const int NUMBER_BUF_LEN = 10; // max strlen of int32

if ( p>sToken && p-sToken<NUMBER_BUF_LEN && ( *p=='\0' || isspace ( *(BYTE*)p ) || IsSpecial(*p) ) )
{
if ( m_pTokenizer->GetToken() && m_pTokenizer->TokenIsBlended() ) // number with blended should be tokenized as usual
{
m_pTokenizer->SkipBlended();
m_pTokenizer->SetBufferPtr ( m_pLastTokenStart );
} else
{
// got a number followed by a whitespace or special, handle it
char sNumberBuf[16];
// got not a very long number followed by a whitespace or special, handle it
char sNumberBuf[NUMBER_BUF_LEN];

int iNumberLen = Min ( (int)sizeof(sNumberBuf)-1, int(p-sToken) );
memcpy ( sNumberBuf, sToken, iNumberLen );
Expand Down Expand Up @@ -612,7 +614,7 @@ int XQParser_t::GetToken ( YYSTYPE * lvalp )
}
}

// not a number, or not followed by a whitespace, so fallback to regular tokenizing
// not a number, long number, or number not followed by a whitespace, so fallback to regular tokenizing
sToken = (const char *) m_pTokenizer->GetToken ();
if ( !sToken )
{
Expand Down

0 comments on commit 92f722b

Please sign in to comment.