Module Name: src Committed By: christos Date: Thu Feb 24 23:48:59 UTC 2011
Modified Files: src/sys/fs/hfs: hfs_subr.c Log Message: simplify and handle unaligned pointer access. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/fs/hfs/hfs_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/hfs/hfs_subr.c diff -u src/sys/fs/hfs/hfs_subr.c:1.14 src/sys/fs/hfs/hfs_subr.c:1.15 --- src/sys/fs/hfs/hfs_subr.c:1.14 Thu Jun 24 09:03:09 2010 +++ src/sys/fs/hfs/hfs_subr.c Thu Feb 24 18:48:59 2011 @@ -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