|
const char *pVar;
we can check (pVar == NULL) for null values.
How to check when the pVar contains bad pointer(not NULL)?
|
|
|
|
|
to check bad ponter for string use
use BOOL IsBadStringPtr(LPCTSTR lpString,WORD uuMaxLen)
for example:
const char *pVar;
if(IsBadStringPtr((LPCTSTR)pVAr,1)==TRUE)
//pVar contains bad pointer or memory is not allocated to pVar
else
//pVar contains memory allocated with it
abhi
|
|
|
|
|
Simply put: you cannot. That's the reason to set pVar=NULL just before immediately after freeing its associated memory.
However it depends on your definition of 'bad pointer' (IMHO a variable wrongly pointing a valid memory area is also 'bad'...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, January 8, 2009 6:48 AM
|
|
|
|
|
Actually the pVar is assigned NULL and passed to a DLL.
The DLL assigned pVar to bad pointer.
|
|
|
|
|
KASR1 wrote: Actually the pVar is assigned NULL and passed to a DLL.
The DLL assigned pVar to bad pointer.
Can you post the code of what the dll is doing ?
|
|
|
|
|
please see reply to pallini.
|
|
|
|
|
Prototype:
typedef HRESULT (STDAPICALLTYPE * LPFPTRANSLATE) (char* psz1, char* &psz2);
second parameter i am getting bad pointer.
|
|
|
|
|
I fixed my (obviuosly ) wrong reply.
What is pVar expected to be by the DLL (i.e. what is the prototype of the DLL 's function)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Its a third party DLL.(we don't have code)
Prototype:
typedef HRESULT (STDAPICALLTYPE * LPFPTRANSLATE) (char* psz1, char* &psz2);
second parameter i am getting bad pointer.
|
|
|
|
|
How do you know it is a "bad" pointer ?
|
|
|
|
|
Program crashes when accessing value from second parameter passed ie., psz2
|
|
|
|
|
KASR1 wrote: Program crashes when accessing value from second parameter passed
...with a particuliar error message by any chance ?
|
|
|
|
|
Throws 'access denied' error message.
|
|
|
|
|
The segfault pretty much tells you that its a bad pointer. If you want to have a look at the properties of the memory address being passed you can do something like:
MEMORY_BASIC_INFORMATION mbi;
VirtualQueryEx(GetCurrentProcess(),pVar,&mbi,sizeof(mbi));
The member mbi.Protect will be probably be PAGE_NOACCESS. But of course you already have this knowledge.
Best Wishes,
-David Delaune
|
|
|
|
|
Yes it works fine.
Thanks a lot.
|
|
|
|
|
Are you calling it this way (assuming 'translate ' as the name of the function pointer)?
char * psz1 = "Hello";
char * psz2;
HRESULT hr = translate( psz1, psz2);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yes. small change as below
char * psz1 = "Hello";
char * psz2 = NULL;
HRESULT hr = translate( psz1, psz2);
|
|
|
|
|
Well, psz2 initialization shouldn't matter.
Have you any documentation of the library?
(Maybe the function has some weird pre-requisite, like psz2 pointing to a client-allocated buffer...I know it doesn't make sense, but several real pieces of code actually does not make sense).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for replying soon.
The below logic given by Randor seems working.
MEMORY_BASIC_INFORMATION mbi;
VirtualQueryEx(GetCurrentProcess(),pVar,&mbi,sizeof(mbi));
if (mbi.Protect == PAGE_NOACCESS)
{
}
|
|
|
|
|
I'm glad about, but doesn't the HRESULT return value give some info about the translate operation?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Well, technically it could be other values. For example you may recieve a ramdom garbage pointer which resolves to a loaded PE image. A better implementation for checking a variable pointer would be:
MEMORY_BASIC_INFORMATION mbi;
VirtualQueryEx(GetCurrentProcess(),pVar,&mbi,sizeof(mbi));
if (mbi.Protect == PAGE_READWRITE && mbi.State = MEM_COMMIT && mbi.Type == MEM_PRIVATE)
{
}
This ensures:
1.) You can read and write to the address.
2.) The address is allocated and committed memory.
3.) The address is within the private region.
At this point the chance of being a good pointer has become substantially higher.
Best Wishes,
-David Delaune
|
|
|
|
|
I'm trying to obtain the Windows Firewall status, which is simple enough using the get_FirewallEnabled method on INetFwProfile. The problem is that this only retrieves the local policy, which could have been overridden by the group policy and so is sometimes wrong.
Does anyone know if there's a way of retrieving the group policy? There's a get_CurrentProfileType on INetFwMgr, but this just seems to return NET_FW_PROFILE_STANDARD regardless of the policy. There's a NEW_FW_POLICY_TYPE enum, but it's not used in any methods that I can find.
Thanks!
|
|
|
|
|
MSDN has examples for work with Firewall did you see
Using Windows Firewall API[^]?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Thanks. I'd read through this documentation, and can't find any way of obtaining the group policy (or indeed even of telling whether or not the local policy is being overridden). Given the existence of the NET_FW_POLICY_TYPE enum, I'd like to think it's possible, but I'm starting to think maybe it's not...
|
|
|
|
|
hello Experts,
I would like to know the basics of how to use SIP protocol using vc++.This is not regards to any project. Just for my self learning.
Thanks,
Himangshu
|
|
|
|