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

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 08, 2000 at 12:28:32PM -0700, Alfred Perlstein wrote:
> * 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.
> 

Arghh! The perils of copy 'n' pasting. I spend ages staring at
it trying to see the error then as soon as someone points it out it
leaps out at me ("wood" and "trees" spring to mind).

Thanks.

> 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."

-- 
		4.4 - The number of the Beastie
________________________________________________________________
51.44°N  FreeBSD - The Power To Serve http://www.freebsd.org
2.057°W  My Webpage http://ukug.uk.freebsd.org/~mark
mailto:marko@freebsd.org                http://www.radan.com



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?20000808204455.J250>