From owner-freebsd-chat Tue Aug 8 12:45:17 2000 Delivered-To: freebsd-chat@freebsd.org Received: from mta03-svc.ntlworld.com (mta03-svc.ntlworld.com [62.253.162.43]) by hub.freebsd.org (Postfix) with ESMTP id 096D337B5A2 for ; Tue, 8 Aug 2000 12:45:14 -0700 (PDT) (envelope-from mark@ukug.uk.freebsd.org) Received: from parish.my.domain ([62.253.88.85]) by mta03-svc.ntlworld.com (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP id <20000808194510.XFOV16423.mta03-svc.ntlworld.com@parish.my.domain>; Tue, 8 Aug 2000 20:45:10 +0100 Received: (from mark@localhost) by parish.my.domain (8.9.3/8.9.3) id UAA03567; Tue, 8 Aug 2000 20:44:55 +0100 (BST) (envelope-from mark) Date: Tue, 8 Aug 2000 20:44:55 +0100 From: Mark Ovens To: Alfred Perlstein Cc: chat@FreeBSD.ORG Subject: Re: C time functions - problem Message-ID: <20000808204455.J250@parish> References: <20000808201807.H250@parish> <20000808122832.I4854@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: <20000808122832.I4854@fw.wintelcom.net>; from bright@wintelcom.net on Tue, Aug 08, 2000 at 12:28:32PM -0700 Organization: Total lack of Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Tue, Aug 08, 2000 at 12:28:32PM -0700, Alfred Perlstein wrote: > * Mark Ovens [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 > > #include > > > > 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