There seems an issue with iRateLerpLength in this code (not your fault). What is it for? it seems to be allays buff_size. 
By the way:  buff_size is unsigned long, which should not be used because it has a target depending size.  

Are you sure the code here and below is save abainst division by Zero?