linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Segfault fix in scsi_id-0.6
@ 2004-09-29  0:45 Patrick Mansfield
  2004-09-29 18:58 ` Dave Dodge
  2004-09-29 20:21 ` Andrew Patterson
  0 siblings, 2 replies; 3+ messages in thread
From: Patrick Mansfield @ 2004-09-29  0:45 UTC (permalink / raw)
  To: linux-hotplug

[following up on hotplug-devel ...]

On Tue, Sep 28, 2004 at 03:33:59PM -0600, Andrew Patterson wrote:
> Hi Patrick,
> 
> I found a segfault when running scsi_id on an IA-64 box.  I assume you
> will get the same behavior on any box where an int is 32 bits and not
> 64.  I have included a patch to fix the problem.  Note the "- (char *)0
> change that I stole from lmdd.
> 
> Andrew
> 
> 
> 
> diff -Nur scsi_id-0.6/scsi_id.c scsi_id-0.6.new/scsi_id.c
> --- scsi_id-0.6/scsi_id.c       2004-07-30 14:33:59.000000000 -0600
> +++ scsi_id-0.6.new/scsi_id.c   2004-09-28 15:24:44.000000000 -0600
> @@ -713,7 +713,7 @@
> 
>  #define ALIGN   512
>         unaligned_buf = malloc(MAX_SERIAL_LEN + ALIGN);
> -       serial = (char*) (((int) unaligned_buf + (ALIGN - 1)) & ~(ALIGN
> - 1));
> +       serial = (char*) (((unaligned_buf - (char *)0) + (ALIGN - 1)) &
> ~(ALIGN - 1));
>         dprintf("buffer unaligned 0x%p; aligned 0x%p\n", unaligned_buf,
> serial); #undef ALIGN

Thanks for pointing this out, patch works fine.

But how about just casting to unsigned long instead? Like:

Index: scsi_id.c
=================================RCS file: /home/patman/CVS/scsi_id/scsi_id/scsi_id.c,v
retrieving revision 1.36
diff -u -r1.36 scsi_id.c
--- scsi_id.c	30 Jul 2004 20:33:59 -0000	1.36
+++ scsi_id.c	29 Sep 2004 00:38:59 -0000
@@ -713,7 +713,8 @@
 
 #define ALIGN   512
 	unaligned_buf = malloc(MAX_SERIAL_LEN + ALIGN);
-	serial = (char*) (((int) unaligned_buf + (ALIGN - 1)) & ~(ALIGN - 1));
+	serial = (char*) (((unsigned long) unaligned_buf + (ALIGN - 1))
+			  & ~(ALIGN - 1));
 	dprintf("buffer unaligned 0x%p; aligned 0x%p\n", unaligned_buf, serial);
 #undef ALIGN
 
-- Patrick Mansfield


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-09-29 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-29  0:45 Segfault fix in scsi_id-0.6 Patrick Mansfield
2004-09-29 18:58 ` Dave Dodge
2004-09-29 20:21 ` Andrew Patterson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).