The compiler message comes from using ctime
at all, but your use will give incorrect results: Both calls to ctime will return the same address to an internal, static, thread-local buffer, meaning your call to printf
will incorrectly display identical dates.
At the minimum, you should do this:
virtual bool onTLSConnect( const CertInfo& info )
{
std::string dateFrom(ctime(reinterpret_cast< const time_t* >(&info.date_from));
std::string dateTo (ctime(reinterpret_cast< const time_t* >(&info.date_to));
printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n"
"from: %s\nto: %s\n",
info.status, info.issuer.c_str(), info.server.c_str(),
info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(),
info.compression.c_str(), dateFrom.c_str(),
dateTo.c_str() );
return true;
}
On the subject of the compiler, you could disable this altogether with a #define
, or you could disable it just when you need it:
virtual bool onTLSConnect( const CertInfo& info )
{
#pragma warning(push)
#pragma warning(disable:4996)
std::string dateFrom(ctime(reinterpret_cast< const time_t* >(&info.date_from));
std::string dateTo (ctime(reinterpret_cast< const time_t* >(&info.date_to));
#pragma warning(pop)
printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n"
"from: %s\nto: %s\n",
info.status, info.issuer.c_str(), info.server.c_str(),
info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(),
info.compression.c_str(), dateFrom.c_str(),
dateTo.c_str() );
return true;
}