title: How to avoid overflow in realloc?
body: <p>One can safely allocate <code>x</code> elements of size <code>y</code> in C by using <code>calloc(x, y)</code> and <code>calloc()</code> will take care of the multiplication <code>x*y</code>. </p>
  
  <p>However <code>realloc()</code> for example only takes the new size as parameter and I was wondering how I could safely realloc <code>x*y</code> bytes using <code>realloc()</code>.</p>
  
  <p>What if <code>x*y</code> doesn't fit in <code>size_t</code>? How does <code>calloc()</code> handle this?</p>