[ale] calling fini
Joseph A. Knapka
jknapka at earthlink.net
Fri Mar 9 11:38:15 EST 2001
There is a memory error in your code. You are passing an
uninitialized pointer to "time()" - the declaration
"time_t* timet" is going to get you a pointer intialized
to the more-or-less random contents of the stack location
at which timet gets allocated. Programming errors
like this are quite capable of causing bizarre and
unpredictable results. For example, by adding the
"char* test" declaration you might be pushing the
declaration of "timet" up the stack to a place that
happens to contain an address used by glibc for
something else.
The "time()" function is intended to be used thus:
time_t tt;
time(&tt);
-- Joe
> Chris Fowler wrote:
>
> Have this interesting problem when running a C program. It only
> happens then I add "char *test" to the code. My only goal was to add
> an 'a' or 'p' to end of output.
>
> output:
>
> 14248:
> 14248: calling fini: /lib/libc.so.6
> 14248:
> 09:53:39
>
> Code
>
> #include <time.h>
>
> void
> main(void)
> {
> int hour = 0;
> int minutes = 0;
> int seconds = 0;
> char *test ='\0';
> time_t *timet;
> struct tm *buf;
>
> time(timet);
> buf = localtime(timet);
>
> hour = buf->tm_hour;
> minutes = buf->tm_min;
> seconds = buf->tm_sec;
>
> if ( hour > 12 )
> {
> hour = hour - 12;
> }
>
> printf("%02d:%02d:%02d\n", hour,minutes,seconds);
> }
-- Joe Knapka
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
More information about the Ale
mailing list