04-30-2014 02:44 AM
Hello
I have a problem with a date conversion. Our function is looking like this:
void GetGlobalMinute(int *iMin)
{
time_t Datum;
char caMonth[100]="", temp2[100]="", String[100]="";
char *temp=(char *)NULL;
int iDay, iYear, iSek, iStd;
// Zeitpunkt festhalten
Datum = time(NULL);
//
temp = ctime(&Datum);
// Datum holen
sscanf(temp, "%s %s %d %s %d", temp2, caMonth, &iDay, String, &iYear);
// Stunden und Minuten erstellen
sscanf(String, "%d:%d:%d", &iStd, iMin, &iSek);
}
Normally this is running fine. No problems with it. But after a couple of days it could happen, that we get a error message like this
Assignment out of bounds pointer: 56352487 bytes past end of array on the function of temp = ctime(&Datum);
The value of the date is: 3607796771.
Then we have a problem with the software.
Does anyone know why this happens? How can we avoid this?
thanks
Oliver
05-23-2014 04:05 AM
Hi Oliver,
seems like you have problems with your allocated memory. I think your program crashes because you try to use memory which is not allocated to your programm.
How often do you call the function within these days?
Why is it neccessary to call this function so often and how do you handle the memory allocation of these pointers?
Maybe you could reallocate the memory before you assign the pointer "temp" to a new value.
Kind regards,
Janina
05-23-2014 06:01 AM
I wonder if you can change your code in order to use CVI functions: GetCurrentDateTime () returns the same value as time (), at least in the integer part. Individual elements can then be extracted with GetDateTimeElements () function on the returned value. This way you can get rid of string scanning and also avoid the eventual problem given by the concurrent use of asctime (see the note on the help for ctime function)