I check this once again and re-analyze this code. I think I has done mistake. After reading this comment once again it seems that second if-statement which I supposed to be unnecessary is necessary... It checks for overflow. When I was analyzing this code before I didn't see it. <div>
<br></div><div>Code above second if-statement can't make allocated_message_size variable less than maximum_message_size normally. But maximum_message_size would be very close to SIZE_MAX, adding an overhead to allocated_message_size can cause an overflow. And then allocated_message_size will be less than maximum_message_size.</div>
<div><br></div><div>I'm sorry for this error and mess. I should be more careful and remember about possibility of overflow.</div>