From owner-freebsd-chat Tue Aug 8 12:28:37 2000 Delivered-To: freebsd-chat@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id A4D2B37B695; Tue, 8 Aug 2000 12:28:33 -0700 (PDT) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e78JSW914401; Tue, 8 Aug 2000 12:28:32 -0700 (PDT) Date: Tue, 8 Aug 2000 12:28:32 -0700 From: Alfred Perlstein To: Mark Ovens Cc: chat@FreeBSD.ORG Subject: Re: C time functions - problem Message-ID: <20000808122832.I4854@fw.wintelcom.net> References: <20000808201807.H250@parish> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: <20000808201807.H250@parish>; from marko@FreeBSD.ORG on Tue, Aug 08, 2000 at 08:18:07PM +0100 Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org * 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. 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