you should check first if the buffer has space to store new message and only then inc rease its size