A difficulty of realloc.

Abstract: The following code has an impressive bug in the book Writing Solid Code)

 pbBuf = (char *)realloc(pbBuf, sizeNew); 
 if (pbBuf != NULL){
     /* do something */ 
 }
 
Can you see the bug? It's a serious bug. pbBuf pointed to a legal address, and sizeNew > 0 when the realloc is called.


Copyright (C) 2005-2006 Yamauchi, Hitoshi
Most recent update : :