aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-08-10 20:30:07 +0200
committercbdev <cb@cbcdn.com>2019-08-10 20:30:07 +0200
commit48bf96602023b2ead855f13477b6f5e26b663b45 (patch)
treedbdcb002c0211b566487c174834a408ba881958c
parentcf93d280af47aea1bf8bdafa30eabb2c2de005b8 (diff)
downloadmidimonster-48bf96602023b2ead855f13477b6f5e26b663b45.tar.gz
midimonster-48bf96602023b2ead855f13477b6f5e26b663b45.tar.bz2
midimonster-48bf96602023b2ead855f13477b6f5e26b663b45.zip
Clean up & check unions
-rw-r--r--backends/artnet.c5
-rw-r--r--backends/evdev.c14
-rw-r--r--backends/evdev.h9
-rw-r--r--backends/midi.c14
-rw-r--r--backends/midi.h10
-rw-r--r--backends/osc.c13
-rw-r--r--backends/osc.h8
-rw-r--r--backends/sacn.c5
8 files changed, 52 insertions, 26 deletions
diff --git a/backends/artnet.c b/backends/artnet.c
index 7f3f08c..8e47d4f 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -54,6 +54,11 @@ int init(){
.shutdown = artnet_shutdown
};
+ if(sizeof(artnet_instance_id) != sizeof(uint64_t)){
+ fprintf(stderr, "ArtNet instance identification union out of bounds\n");
+ return 1;
+ }
+
//register backend
if(mm_backend_register(artnet)){
fprintf(stderr, "Failed to register ArtNet backend\n");
diff --git a/backends/evdev.c b/backends/evdev.c
index 7a7913d..bd2098d 100644
--- a/backends/evdev.c
+++ b/backends/evdev.c
@@ -18,15 +18,6 @@
#define BACKEND_NAME "evdev"
-typedef union {
- struct {
- uint32_t pad;
- uint16_t type;
- uint16_t code;
- } fields;
- uint64_t label;
-} evdev_channel_ident;
-
static struct {
uint8_t detect;
} evdev_config = {
@@ -46,6 +37,11 @@ int init(){
.shutdown = evdev_shutdown
};
+ if(sizeof(evdev_channel_ident) != sizeof(uint64_t)){
+ fprintf(stderr, "evdev channel identification union out of bounds\n");
+ return 1;
+ }
+
if(mm_backend_register(evdev)){
fprintf(stderr, "Failed to register evdev backend\n");
return 1;
diff --git a/backends/evdev.h b/backends/evdev.h
index f89e362..b26664b 100644
--- a/backends/evdev.h
+++ b/backends/evdev.h
@@ -44,3 +44,12 @@ typedef struct /*_evdev_instance_model*/ {
struct libevdev_uinput* output_ev;
#endif
} evdev_instance_data;
+
+typedef union {
+ struct {
+ uint32_t pad;
+ uint16_t type;
+ uint16_t code;
+ } fields;
+ uint64_t label;
+} evdev_channel_ident; \ No newline at end of file
diff --git a/backends/midi.c b/backends/midi.c
index 9c6ba80..5b8e561 100644
--- a/backends/midi.c
+++ b/backends/midi.c
@@ -4,15 +4,6 @@
#define BACKEND_NAME "midi"
static snd_seq_t* sequencer = NULL;
-typedef union {
- struct {
- uint8_t pad[5];
- uint8_t type;
- uint8_t channel;
- uint8_t control;
- } fields;
- uint64_t label;
-} midi_channel_ident;
enum /*_midi_channel_type*/ {
none = 0,
@@ -44,6 +35,11 @@ int init(){
.shutdown = midi_shutdown
};
+ if(sizeof(midi_channel_ident) != sizeof(uint64_t)){
+ fprintf(stderr, "MIDI channel identification union out of bounds\n");
+ return 1;
+ }
+
if(snd_seq_open(&sequencer, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0){
fprintf(stderr, "Failed to open ALSA sequencer\n");
return 1;
diff --git a/backends/midi.h b/backends/midi.h
index 556706f..5ec17ea 100644
--- a/backends/midi.h
+++ b/backends/midi.h
@@ -15,3 +15,13 @@ typedef struct /*_midi_instance_data*/ {
char* read;
char* write;
} midi_instance_data;
+
+typedef union {
+ struct {
+ uint8_t pad[5];
+ uint8_t type;
+ uint8_t channel;
+ uint8_t control;
+ } fields;
+ uint64_t label;
+} midi_channel_ident; \ No newline at end of file
diff --git a/backends/osc.c b/backends/osc.c
index 77bbde4..beb5527 100644
--- a/backends/osc.c
+++ b/backends/osc.c
@@ -13,14 +13,6 @@
#define osc_align(a) ((((a) / 4) + (((a) % 4) ? 1 : 0)) * 4)
#define BACKEND_NAME "osc"
-typedef union {
- struct {
- uint32_t channel;
- uint32_t parameter;
- } fields;
- uint64_t label;
-} osc_channel_ident;
-
static struct {
uint8_t detect;
} osc_global_config = {
@@ -40,6 +32,11 @@ int init(){
.shutdown = osc_shutdown
};
+ if(sizeof(osc_channel_ident) != sizeof(uint64_t)){
+ fprintf(stderr, "OSC channel identification union out of bounds\n");
+ return 1;
+ }
+
//register backend
if(mm_backend_register(osc)){
fprintf(stderr, "Failed to register OSC backend\n");
diff --git a/backends/osc.h b/backends/osc.h
index b2aaea7..ab19463 100644
--- a/backends/osc.h
+++ b/backends/osc.h
@@ -66,3 +66,11 @@ typedef struct /*_osc_instance_data*/ {
//peer fd
int fd;
} osc_instance_data;
+
+typedef union {
+ struct {
+ uint32_t channel;
+ uint32_t parameter;
+ } fields;
+ uint64_t label;
+} osc_channel_ident; \ No newline at end of file
diff --git a/backends/sacn.c b/backends/sacn.c
index 2f418e5..470e3bd 100644
--- a/backends/sacn.c
+++ b/backends/sacn.c
@@ -44,6 +44,11 @@ int init(){
.shutdown = sacn_shutdown
};
+ if(sizeof(sacn_instance_id) != sizeof(uint64_t)){
+ fprintf(stderr, "sACN instance identification union out of bounds\n");
+ return 1;
+ }
+
//register the backend
if(mm_backend_register(sacn)){
fprintf(stderr, "Failed to register sACN backend\n");