Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

MFC TreeView issue

AsmGuru62AsmGuru62 Member Posts: 6,519
[blue]Just recently I have come across a problem in MFC code. There is a method:[/blue]
[code]
CTreeCtrl::GetItemData (HTREEITEM hItem)
{
...
}
[/code][blue]
This method will return garbage pointer in the case of invalid HTREEITEM passed in. It first will fire an ASSERT() in debug build, but then return uninitialized variable from stack.

In our case (at my work) we used the 'delete' statement on the return value and obviously heap corruption followed and our system failed at some point after that.

I understand that it is our code which passes the invalid HTREEITEM (and we will locate and fix that code), but MFC is a serious library - not some wacked free library from the Web. It should not fail in that manner. Instead, it should return NULL from that method.

To fix that issue I wrote my own GetItemData() with a checking of the return value from TVM_GETITEM message and that saved the day (for now).
[/blue]

Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    [b][red]This message was edited by stober at 2007-1-14 7:26:7[/red][/b][hr]
    I suppose you've heard the old aphorism: garbage in, garbage out. :-)


  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [b][red]This message was edited by stober at 2007-1-14 7:26:7[/red][/b][hr]
    : I suppose you've heard the old aphorism: garbage in, garbage out. :-)
    :
    :
    :
    [blue]I disagree. If I use most API to do things for me and pass bad values to these API - they will return NULL or FALSE in most cases, but not MFC in that particular case. Not a serious library, I suppose.[/blue]

Sign In or Register to comment.