I've got a function that takes a pointer to a buffer, and the size of that buffer (via a pointer). If the buffer's not big enough, it returns an error value and sets the required length in the out-param:
// FillBuffer is defined in another compilation unit (OBJ file).
// Whole program optimization is off.
int FillBuffer(__int_bcount_opt(*pcb) char *buffer, size_t *pcb);
I call it like this:
size_t cb = 12;
char *p = (char *)malloc(cb);
if (!p)
return ENOMEM;
int result;
for (;;)
{
result = FillBuffer(p, &cb);
if (result == ENOBUFS)
{
char *q = (char *)realloc(p, cb);
if (!q)
{
free(p);
return ENOMEM;
}
p = q;
}
else
break;
}
Visual C++ 2010 (with code analysis cranked to the max) complains with 'warning C6001: Using uninitialized memory 'p': Lines: ...'
. It reports line numbers covering pretty much the entire function.
Visual C++ 2008 doesn't. As far as I can tell, this code's OK. What am I missing? Or what is VC2010 missing?