added doubling of buffer size in checkSectionSize when missing space. Used 1024 instead of 1000 as start size

This commit is contained in:
csoler 2016-11-25 21:06:40 +01:00
parent 5fbc263a36
commit d975a18fd6
2 changed files with 16 additions and 3 deletions

View File

@ -54,4 +54,4 @@ static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change!
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min
static const uint32_t FL_BASE_TMP_SECTION_SIZE = 1000 ;
static const uint32_t FL_BASE_TMP_SECTION_SIZE = 4096 ;

View File

@ -109,13 +109,26 @@ private:
static bool checkSectionSize(unsigned char *& buff,uint32_t& buff_size,uint32_t offset,uint32_t S)
{
// This tests avoids an infinite loop when growing new size
if(offset + S + SECTION_HEADER_MAX_SIZE > 0x8fffffff)
return false ;
if(offset + S + SECTION_HEADER_MAX_SIZE > buff_size)
{
buff = (unsigned char *)realloc(buff,offset + S + SECTION_HEADER_MAX_SIZE) ;
buff_size = offset + S + SECTION_HEADER_MAX_SIZE;
uint32_t new_size = (buff_size == 0)?512:buff_size ;
while(new_size < offset + S + SECTION_HEADER_MAX_SIZE)
new_size <<= 1 ;
buff = (unsigned char *)realloc(buff,new_size) ;
if(!buff)
{
buff_size = 0 ;
return false ;
}
buff_size = new_size ;
}
return true ;
}