Re: Regarding global variables memory allocation and gtime funtion



sunil <sunil.vvn@xxxxxxxxx> writes:

....
time(&ltime);
newtime = gmtime(&ltime);
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.
.



Relevant Pages

  • Re: Regarding global variables memory allocation and gtime funtion
    ... After executing the gmtime function, ... And the program is trying to access the null values and it is failing. ... IOW, the bug is still present, but you have ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.apps)
  • Re: [opensuse] Scary enough for Halloween...
    ... The point is that if there is a bug in a piece of software, ... hackers rarely need any help to get their code onto ... flash in itself already means you are executing code on your ... closed source binary and ANY open source program. ...
    (SuSE)
  • Re: [opensuse] Scary enough for Halloween...
    ... The point is that if there is a bug in a piece of software, ... flash in itself already means you are executing code on your ... It runs in a sandbox as with all other virtual machines that execute ... of a local cache will not help you in any way ...
    (SuSE)
  • Re: repaint method and design question
    ... executing on another thread. ... that depends on how you call notifyObservers(). ... It was a bug. ... The method notifyObservers() says, "Each observer has ...
    (comp.lang.java.programmer)
  • Re: Regarding global variables memory allocation and gtime funtion
    ... static struct tm *newtime; ... It is working fine on unix boxes. ... After executing the gmtime function, ... And the program is trying to access the null values and it is failing. ...
    (comp.unix.solaris)