From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Dodge Date: Wed, 29 Sep 2004 18:58:04 +0000 Subject: Re: Segfault fix in scsi_id-0.6 Message-Id: <20040929190347.GA28198@basmati> List-Id: References: <20040929004539.GA2282@beaverton.ibm.com> In-Reply-To: <20040929004539.GA2282@beaverton.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org On Tue, Sep 28, 2004 at 05:45:39PM -0700, Patrick Mansfield wrote: > On Tue, Sep 28, 2004 at 03:33:59PM -0600, Andrew Patterson wrote: > > + serial = (char*) (((unaligned_buf - (char *)0) + (ALIGN - 1)) & > > ~(ALIGN - 1)); Quick comment: the C compiler will treat the (char*)0 as a null pointer constant. C makes no guarantee that the resulting value will have anything to do with address 0. I believe there are architectures where a null pointer has all-bits-on or some other non-zero representation, though I don't know if Linux has ever been made to run on any of them. > But how about just casting to unsigned long instead? Like: > + serial = (char*) (((unsigned long) unaligned_buf + (ALIGN - 1)) > + & ~(ALIGN - 1)); None of this pointer manipulation is technically defined to work, but from a practical standpoint this will probably be safe. There's still the possibility that an unsigned long can't hold all pointer values. If you're willing to rely on a C99 construct, you could include and use uintptr_t instead. -Dave Dodge ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel