0

Coverity has pointed out a bug about deleting void pointer. The code is as below:

void *pbits=(void *)new char[((bmp.bmWidth*bitspixel+31)/32)*bmp.bmHeight*4];
result=GetDIBits(pDC->GetSafeHdc(),HBITMAP(*pbitmap),0,bmp.bmHeight,pbits,bitmapinfo,DIB_RGB_COLORS);

char curdir[100];
if(!GetCurrentDirectory(100,curdir))
{
    delete [] pbits;    
    return;
}

Can you please help me on what is incorrect and how can I solve it?

Many thanks

Best Regards

Chintan

chintan s
  • 6,170
  • 16
  • 53
  • 86
  • 1
    Not sure why we have to guess at the warning it generates. High odds it isn't too happy about you using delete[] on a void*. So just don't use void*, a char* will work fine as well. – Hans Passant Jul 11 '13 at 12:04

2 Answers2

1

Just use char* for the type of pbits.

manuell
  • 7,528
  • 5
  • 31
  • 58
0

A delete on a void * is actually undefined; that's why the tool is reporting something. Just cast pbits when passing it to GetDIBits and you'll solve your issue.

neuroo
  • 51
  • 1
  • 3