Use offsetof() to avoid some casts from pointers to integers (of a

possibly different size).
This commit is contained in:
Bruce Evans 1998-08-15 21:36:16 +00:00
parent 38a0ff129f
commit 8705accbe7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=38341
3 changed files with 9 additions and 3 deletions

View File

@ -21,6 +21,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stddef.h>
#ifdef __FreeBSD__
# include <gnu/i386/isa/sound/awe_config.h>
#else
@ -3296,7 +3298,7 @@ awe_load_guspatch(const char *addr, int offs, int size, int pmgr_flag)
int note, free_sample, free_info;
int rc;
sizeof_patch = (int)((long)&patch.data[0] - (long)&patch); /* header size */
sizeof_patch = offsetof(struct patch_info, data); /* header size */
if (size < sizeof_patch) {
printk("AWE32 Error: Patch header too short\n");
return RET_ERROR(EINVAL);

View File

@ -27,6 +27,8 @@
*
*/
#include <stddef.h>
#include <i386/isa/sound/sound_config.h>
#include <i386/isa/sound/ultrasound.h>
#include <i386/isa/sound/gus_hw.h>
@ -1569,7 +1571,7 @@ guswave_load_patch(int dev, int format, snd_rw_buf * addr,
u_long blk_size, blk_end, left, src_offs, target;
sizeof_patch = (long) &patch.data[0] - (long) &patch; /* Header size */
sizeof_patch = offsetof(struct patch_info, data); /* Header size */
if (format != GUS_PATCH) {
printf("GUS Error: Invalid patch format (key) 0x%x\n", format);

View File

@ -30,6 +30,8 @@
#define USE_SEQ_MACROS
#define USE_SIMPLE_MACROS
#include <stddef.h>
#include <i386/isa/sound/sound_config.h>
#if defined(CONFIGURE_SOUNDCARD) /* && defined(CONFIG_MIDI) */
@ -448,7 +450,7 @@ midi_synth_load_patch(int dev, int format, snd_rw_buf * addr,
int i;
unsigned long left, src_offs, eox_seen = 0;
int first_byte = 1;
int hdr_size = (unsigned long) &sysex.data[0] - (unsigned long) &sysex;
int hdr_size = offsetof(struct sysex_info, data);
leave_sysex(dev);