Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Aug 2000 12:28:32 -0700
From:      Alfred Perlstein <bright@wintelcom.net>
To:        Mark Ovens <marko@FreeBSD.ORG>
Cc:        chat@FreeBSD.ORG
Subject:   Re: C time functions - problem
Message-ID:  <20000808122832.I4854@fw.wintelcom.net>
In-Reply-To: <20000808201807.H250@parish>; from marko@FreeBSD.ORG on Tue, Aug 08, 2000 at 08:18:07PM %2B0100
References:  <20000808201807.H250@parish>

next in thread | previous in thread | raw e-mail | index | archive | help
* Mark Ovens <marko@FreeBSD.ORG> [000808 12:21] wrote:
> Can anyone tell me why the call to localtime() in the code below
> should segfault in tzset()?
> 
> Running it in the debugger shows that ``t'' is set to a sensible
> value.
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x280be4c8 in tzset () from /usr/lib/libc.so.4
> 
> 
> #include <stdio.h>
> #include <time.h>
>     
> int main() {
>     	struct tm *timeptr;
>     	char buf[BUFSIZ];
>     	size_t size;
>     	time_t t;
>       
>     	tzset;
>     
>     	t = time((time_t *)0);
>     	timeptr = localtime((time_t *)t);
>     
> 	 .....

Please don't do disgusting things with casts.

Do not cast a time_t to a time_t *, they aren't the same.

Don't cast 0 to a pointer type, use NULL.

Remove the overzealous casting and your programming error should
become clear.

-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
"I have the heart of a child; I keep it in a jar on my desk."


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000808122832.I4854>