开发者

application crash at strncpy in VS2008

I get an access violation at strncpy in the below code.

if(WaitForSingleObject(RdStatShared.hMutex, INFINITE) == WAIT_OBJECT_0)
{
    if(RdStatShared.Resp.itemLength != NULL)
    {                   
        strncpy((char*)TData[53], (char*)RdStatShared.Resp.itemLength, (size_t)0x01);
    }
    ReleaseMutex(RdStatShared.hMutex);
}

RdStatShared is开发者_开发百科 a shared object used across project. Since it is updated randomly, I wanted to lock the object before reading it. TData is BYTE type of length 1024 and itemLength is a UCHAR.

While debugging code, in the assembly code i see that access violation accurred when copying source string into a temporary buffer. Can any one tell why access violation occurred at strncpy?

Thanks for any useful information.

Lakshmi.


The second argument to strncpy is the location to copy to, and you seem to be passing RdStatShared.Resp.itemLength, which sounds suspiciously like the size of something, and not like a pointer to a character buffer. If you want to interpret it as such, then you probably need to pass a pointer to it, not the thing itself; i.e., (char*) &(RdStatShared.Resp.itemLength) .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜