Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/hfs simplify and handle unaligned pointer access.



details:   https://anonhg.NetBSD.org/src/rev/cc9c703dd49a
branches:  trunk
changeset: 762649:cc9c703dd49a
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Feb 24 23:48:59 2011 +0000

description:
simplify and handle unaligned pointer access.

diffstat:

 sys/fs/hfs/hfs_subr.c |  45 ++++++++++++++-------------------------------
 1 files changed, 14 insertions(+), 31 deletions(-)

diffs (86 lines):

diff -r 0902624619bb -r cc9c703dd49a sys/fs/hfs/hfs_subr.c
--- a/sys/fs/hfs/hfs_subr.c     Thu Feb 24 20:03:41 2011 +0000
+++ b/sys/fs/hfs/hfs_subr.c     Thu Feb 24 23:48:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hfs_subr.c,v 1.14 2010/06/24 13:03:09 hannken Exp $    */
+/*     $NetBSD: hfs_subr.c,v 1.15 2011/02/24 23:48:59 christos Exp $   */
 
 /*-
  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */                                     
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hfs_subr.c,v 1.14 2010/06/24 13:03:09 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hfs_subr.c,v 1.15 2011/02/24 23:48:59 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -366,55 +366,38 @@
 uint16_t be16tohp(void** inout_ptr)
 {
        uint16_t        result;
-       uint16_t *ptr;
        
-       if(inout_ptr==NULL)
+       if(inout_ptr == NULL)
                return 0;
                
-       ptr = *inout_ptr;
-
-       result = be16toh(*ptr);
-
-       ptr++;
-       *inout_ptr = ptr;
+       memcpy(&result, *inout_ptr, sizeof(result));
+       *inout_ptr = (char *)*inout_ptr + sizeof(result);
        
-       return result;
+       return be16toh(result);
 }
 
 uint32_t be32tohp(void** inout_ptr)
 {
        uint32_t        result;
-       uint32_t *ptr;
        
-       if(inout_ptr==NULL)
+       if(inout_ptr == NULL)
                return 0;
 
-       ptr = *inout_ptr;
-
-       result = be32toh(*ptr);
-
-       ptr++;
-       *inout_ptr = ptr;
-       
-       return result;
+       memcpy(&result, *inout_ptr, sizeof(result));
+       *inout_ptr = (char *)*inout_ptr + sizeof(result);
+       return be32toh(result);
 }
 
 uint64_t be64tohp(void** inout_ptr)
 {
        uint64_t        result;
-       uint64_t *ptr;
        
-       if(inout_ptr==NULL)
+       if(inout_ptr == NULL)
                return 0;
 
-       ptr = *inout_ptr;
-
-       result = be64toh(*ptr);
-
-       ptr++;
-       *inout_ptr = ptr;
-       
-       return result;
+       memcpy(&result, *inout_ptr, sizeof(result));
+       *inout_ptr = (char *)*inout_ptr + sizeof(result);
+       return be64toh(result);
 }
 
 enum vtype



Home | Main Index | Thread Index | Old Index