diff options
author | bde <bde@FreeBSD.org> | 1998-08-15 23:06:38 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1998-08-15 23:06:38 +0000 |
commit | c96f169902b2f0814f47953253986e524b1139f3 (patch) | |
tree | fd1edc77fdc3a74eab6143c17dc6b232c3a1aa31 /sys/scsi | |
parent | a1f9eb2f926345f381c5c3a67c79d747f93720c6 (diff) | |
download | FreeBSD-src-c96f169902b2f0814f47953253986e524b1139f3.zip FreeBSD-src-c96f169902b2f0814f47953253986e524b1139f3.tar.gz |
Cast to `char *' instead of to u_long to help add byte offsets to
pointers. Neither is portable, but "correct" casts to integral
types are much uglier - they lead to expressions like
ptr = (struct struct_with_too_long_a_name *)(void *)(uintptr_t)
((uintptr_t)(void *)ptr + offset);
Here the cast to the struct pointer is to match the surrounding
style of this file (and not depend on C's feature of properly
converting `void *' on assignment or cast), the `void *' casts are
because uintptr_t is only specified to work on `void *' pointers
(I missed this in about 100 lines of previous changes from [u]long
to [u]intptr_t), the outer cast to a uintptr_t is in case the
addition promoted the type, and the inner cast to a uintptr_t
corresponds to the one cast to an integer in the original code.
Don't depend on gcc's feature of casting lvalues.
Diffstat (limited to 'sys/scsi')
-rw-r--r-- | sys/scsi/ch.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index 3ba80fb..9b970fb 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ch.c,v 1.46 1998/06/07 17:12:47 dfr Exp $ + * $Id: ch.c,v 1.47 1998/06/17 14:13:13 bde Exp $ */ #include "opt_devfs.h" @@ -544,7 +544,7 @@ ch_usergetelemstatus(sc, chet, uptr) goto done; st_hdr = (struct read_element_status_header *)data; - pg_hdr = (struct read_element_status_page_header *)((u_long)st_hdr + + pg_hdr = (struct read_element_status_page_header *)((char *)st_hdr + sizeof(struct read_element_status_header)); desclen = scsi_2btou(pg_hdr->edl); @@ -583,12 +583,13 @@ ch_usergetelemstatus(sc, chet, uptr) user_data = (u_int8_t *)malloc(avail, M_DEVBUF, M_WAITOK); - desc = (struct read_element_status_descriptor *)((u_long)data + + desc = (struct read_element_status_descriptor *)((char *)data + sizeof(struct read_element_status_header) + sizeof(struct read_element_status_page_header)); for (i = 0; i < avail; ++i) { user_data[i] = desc->flags1; - (u_long)desc += desclen; + desc = (struct read_element_status_descriptor *) + ((char *)desc + desclen); } /* Copy flags array out to userspace. */ |