Developing a program in VC++ using Win32 API;s for Windows 7 32-bit OS. I used strncpy_s function mentioned in string.h for secure copying, but it crashes in some machines.
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_ _CRTIMP_ALTERNATIVE errno_t __cdecl strncpy_s(_Out_z_cap_(_SizeInBytes) char * _Dst, _In_ rsize_t _SizeInBytes, _In_z_ const char * _Src, _In_ rsize_t _MaxCount);
#endif
Here is the stacktrace
> msvcr100.dll!malloc(unsigned int size) Line 89 + 0x3b bytes C
mfc100u.dll!operator new(unsigned int nSize) Line 323 + 0x5 bytes C++
MyTest.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Copy(unsigned int _Newsize, unsigned int _Oldlen) Line 1933 + 0x16 bytes C++
MyTest.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr, unsigned int _Count) Line 920 + 0x26 bytes C++
MyTest.exe!std::basic_stringbuf<char,std::char_traits<char>,std::allocator<char> >::str() Line 97 + 0x2a bytes C++
MyTest.exe!std::basic_ostringstream<char,std::char_traits<char>,std::allocator<char> >::str() Line 593 + 0x12 bytes C++
MyTest.exe!Trace<TraceToFile>::~Trace<TraceToFile>() Line 174 + 0xa bytes C++
MyTest.exe!CCommonUtilities::sendDataToClient(std::basic_string<char,std::char_traits<char>,std::allocator<char> > strJson, int nCommandID, std::basic_string<char,std::char_traits<char>,std::allocator<char> > strFuncName, int nLineNumber, int nClientKey) Line 320 C++
MyTest.exe!CConnectionManager::AddConnectionThread(void * p_Param) Line 270 + 0x74 bytes C++
Based on this, can someone point if this is issue with strncpy_s or programming error ?
I never get issue if I try to debug the code. It always come when we execute this binary.
Many Thanks in advance.