validating handles and pointers
-
Good point but still before using it, it maybe necessary to check its validity. thanks
Electronic75 wrote:
...it maybe necessary to check its validity.
Which is what Cedric has been trying to tell you (by comparing the pointer to
NULL
)."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Before running CloseHandle() I terminate those threads. Still I'm sure most of you guys know about the function that checks validity of a pointer to be in valid memory space. I've used it so many times and I now I just forgot that and I can't find it in MSDN crap.
Electronic75 wrote:
Still I'm sure most of you guys know about the function that checks validity of a pointer to be in valid memory space.
AfxIsValidAddress()
is a wrapper aroundIsBadReadPtr()
andIsBadWritePtr()
."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Electronic75 wrote:
When one defines a pointer [...] it is not null then
It should be. Always initialize your variables!
Electronic75 wrote:
t should be checked especially if some naughty functions have played with it before
Do not let any naughty functions touch your private parts! Do not program naughty functions in the first place. If naughty functions are made by someone else and keep doing horrible things to the objects you gave them pointers to, hand them a copy of the object, and keep the original with yourself.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"jhwurmbach wrote:
It should be. Always initialize your variables!
Of course I initialize pointers but not to NULL to some values.
jhwurmbach wrote:
Do not let any naughty functions touch your private parts!
Well, I have no problem with girls :laugh: @ DavidCrow, I understood what cedric said but my point is when it has been given a value somewhere in the program and there is a possibility that value dose not exist anymore so the value is wrong then still I need to check it. Yes when I didn't need the pointer anymore I'll assign null to it and then compare it to null before using it.
jhwurmbach wrote:
Do not program naughty functions in the first place. If naughty functions are made by someone else and keep doing horrible things to the objects you gave them pointers to, hand them a copy of the object, and keep the original with yourself.
Actually the naughty functions were also written by me but about 2-3 years ago and it is part of a scary and big project. Now I do not have enough time(as ever) and I have to add some additional functionalities before having time to inspect all the codes. I will check all the codes whenever I had time but now there is a big crowd who are ready to kill me if I do not give this software to them until the deadline(and the deadline already has been passed :~) but happily as I said in another post problem solved it was a silly mistake of mine :cool:
-
jhwurmbach wrote:
It should be. Always initialize your variables!
Of course I initialize pointers but not to NULL to some values.
jhwurmbach wrote:
Do not let any naughty functions touch your private parts!
Well, I have no problem with girls :laugh: @ DavidCrow, I understood what cedric said but my point is when it has been given a value somewhere in the program and there is a possibility that value dose not exist anymore so the value is wrong then still I need to check it. Yes when I didn't need the pointer anymore I'll assign null to it and then compare it to null before using it.
jhwurmbach wrote:
Do not program naughty functions in the first place. If naughty functions are made by someone else and keep doing horrible things to the objects you gave them pointers to, hand them a copy of the object, and keep the original with yourself.
Actually the naughty functions were also written by me but about 2-3 years ago and it is part of a scary and big project. Now I do not have enough time(as ever) and I have to add some additional functionalities before having time to inspect all the codes. I will check all the codes whenever I had time but now there is a big crowd who are ready to kill me if I do not give this software to them until the deadline(and the deadline already has been passed :~) but happily as I said in another post problem solved it was a silly mistake of mine :cool:
Electronic75 wrote:
my point is when it has been given a value somewhere in the program and there is a possibility that value dose not exist anymore so the value is wrong then still I need to check it.
Where does this possibility come from? THAT is the task you need to solve! Wherever you delete an object, you need to change the pointer value to NULL. Thats all, folks
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"