Re: Regarding global variables memory allocation and gtime funtion
- From: Paul Pluzhnikov <ppluzhnikov-nsp@xxxxxxxxx>
- Date: Wed, 27 Feb 2008 23:17:29 -0800
sunil <sunil.vvn@xxxxxxxxx> writes:
....
time(<ime);
newtime = gmtime(<ime);
memset(timeString,'\0',TIMESTAMP_SIZE);
The memset above is likely unnecessary ...
strftime(timeString, TIMESTAMP_SIZE,"%Y-%m-%d-%X%z------",newtime);
And am using the above timestring variable to print the timestamp.
It is working fine on unix boxes.
It is failing in some boxes after printing some log messages.
After executing the gmtime function, the values of the internal
structures are becoming null.
And the program is trying to access the null values and it is failing.
Above code is not thread-safe. If you are doing this in a
multi-threaded program, then you deserve exactly what you got. Use
gmtime_r() instead.
If I make the above time related variables to static(earlier the
variables are global) then the program is executing fine without any
problems.
If your program is single-threaded, then you have a buffer overflow
bug elsewhere, and by making the variables static simply changes
the layout of final executable, such that some other variable is
getting stepped on. IOW, the bug is still present, but you have
yet to observe it.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.
- Follow-Ups:
- References:
- Prev by Date: Re: Is a binary with this libraries portable
- Next by Date: Re: Is a binary with this libraries portable
- Previous by thread: Regarding global variables memory allocation and gtime funtion
- Next by thread: Re: Regarding global variables memory allocation and gtime funtion
- Index(es):
Relevant Pages
|