[interfacekit] Bug in Syscursor code
- From: "burton666@xxxxxxxxx" <burton666@xxxxxxxxx>
- To: "interfacekit" <interfacekit@xxxxxxxxxxxxx>
- Date: Thu, 30 Oct 2003 11:22:43 +0100
I think I just found a bug in SysCursor code:
const char *CursorSet::GetName(void)
{
BString name;
if(FindString("name",&name)==B_OK)
return name.String();
return NULL;
}
That code isn't right, since as soon as the function returns, the buffer
allocated by the BString object
will be freed, and name.String() will be no longer valid.
A nicer solution can be:
const char *CursorSet::GetName(void)
{
const char *name = NULL;
if(FindString("name", &name) == B_OK)
return name;
return NULL;
}
P.S: This kind of bug is very common (and not so easy to notice, since you can
get various results), so maybe everyone (me included :PP) can go over their
code to make sure they don't make the same mistake.
- Follow-Ups:
- [interfacekit] Re: Bug in Syscursor code
- From: DarkWyrm
Other related posts:
- » [interfacekit] Bug in Syscursor code
- » [interfacekit] Re: Bug in Syscursor code
- [interfacekit] Re: Bug in Syscursor code
- From: DarkWyrm