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.
This commit is contained in:
parent
160bd4c62f
commit
7cfd5f54cf
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user