LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

out of bounds pointer

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

0 Kudos
Message 1 of 3
(4,517 Views)

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

0 Kudos
Message 2 of 3
(4,369 Views)

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)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(4,361 Views)