By accident I came across this behavior and would like to know if this is expected (does not look right to me).
I force an error in one particular tm-structure and all others become corrupted.
This is the code (stripped down to a minimun to reproduce the problem)
int main()
{
cout << "----- Bug test - tm struc -----" << endl;
//--------------------------------------------
//--- Setup struct tm ---
time_t timet_Now = time(NULL);
struct tm* tm1 = localtime(&timet_Now);
struct tm* tm2 = localtime(&timet_Now);
//--- Verify OK - cout shows "28/10/2016"---
cout << tm1->tm_mday << " " << tm1->tm_mon << " " << tm1->tm_year << endl;
cout << tm2->tm_mday << " " << tm2->tm_mon << " " << tm2->tm_year << endl;
// ... so far, so good
// --- Force an error in a different tm struct (xxtm)
time_t xtimet = 1464778020000;
struct tm* xxtm = localtime(&xtimet); //<<< xxtm = null - no runtime error
//--- tm1 and tm2 are now corrupted - cout shows "-1/-1/-1"
cout << tm1->tm_mday << " " << tm1->tm_mon << " " << tm1->tm_year << endl;
cout << tm2->tm_mday << " " << tm2->tm_mon << " " << tm2->tm_year << endl;
//--- This next line crashes the application, as tm1 is corrupted
char* c = asctime(tm1);
return 0;
}
The crash error is: Unhandled exception at 0x0FA520B5 (ucrtbased.dll) in MyTest.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.