I have a function that takes a pointer to a buffer and the size of this buffer (via a pointer). If the buffer is not large enough, it returns an error value and sets the required length in out-param:
int FillBuffer(__int_bcount_opt(*pcb) char *buffer, size_t *pcb);
I call it this way:
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 maximum code analysis) complains about 'warning C6001: Using uninitialized memory 'p': Lines: ...'. It reports line numbers covering almost the entire function.
Visual C ++ 2008 no. As far as I can tell, this code is OK. What am I missing? Or what's missing VC2010?
source
share