[interfacekit] Re: Bug in Syscursor code
- From: "DarkWyrm" <bpmagic@xxxxxxxxxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Thu, 30 Oct 2003 20:00:43 -0500 EST
> 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.
Thanks for the tip. I'll have to check the rest of the code I've
written for the very same kind of bug - there are probably quite a few.
--DW
- References:
- [interfacekit] Bug in Syscursor code
- From: burton666@xxxxxxxxx
Other related posts:
- » [interfacekit] Bug in Syscursor code
- » [interfacekit] Re: Bug in Syscursor code
- [interfacekit] Bug in Syscursor code
- From: burton666@xxxxxxxxx