diff options
author | Chase Douglas <chase.douglas@canonical.com> | 2012-02-10 10:48:44 -0800 |
---|---|---|
committer | Chase Douglas <chase.douglas@canonical.com> | 2012-02-10 13:20:48 -0800 |
commit | 146edc2baad1388f49a7a857c2003faa171876c7 (patch) | |
tree | 55428f5c0dcf7ecefadaadfb68589982f63bf5b2 | |
parent | 49f6109032f2ce6171d1aad02672479d2c78c083 (diff) |
Allocate proto data in eventcomm-test
Provide a helper function for allocating proto data and use it in
eventcomm-test. This ensures a null pointer for priv->proto_data is not
dereferenced.
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/eventcomm.c | 8 | ||||
-rw-r--r-- | src/eventcomm.h | 5 | ||||
-rw-r--r-- | test/eventcomm-test.c | 6 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/eventcomm.c b/src/eventcomm.c index ce26934..d7d1f86 100644 --- a/src/eventcomm.c +++ b/src/eventcomm.c @@ -83,6 +83,12 @@ struct eventcomm_proto_data #endif }; +struct eventcomm_proto_data * +EventProtoDataAlloc(void) +{ + return calloc(1, sizeof(struct eventcomm_proto_data)); +} + #ifdef HAVE_MTDEV static int num_slots(const struct eventcomm_proto_data *proto_data) @@ -940,7 +946,7 @@ EventReadDevDimensions(InputInfoPtr pInfo) int i; #endif - proto_data = calloc(1, sizeof(struct eventcomm_proto_data)); + proto_data = EventProtoDataAlloc(); priv->proto_data = proto_data; #ifdef HAVE_MTDEV diff --git a/src/eventcomm.h b/src/eventcomm.h index 1938d5f..70bfc18 100644 --- a/src/eventcomm.h +++ b/src/eventcomm.h @@ -36,6 +36,11 @@ #define DEV_INPUT_EVENT "/dev/input" #define EVENT_DEV_NAME "event" +struct eventcomm_proto_data; + +extern struct eventcomm_proto_data * +EventProtoDataAlloc(void); + extern Bool EventReadHwState(InputInfoPtr pInfo, struct CommData *comm, struct SynapticsHwState *hwRet); diff --git a/test/eventcomm-test.c b/test/eventcomm-test.c index 60fd0ef..c9d8888 100644 --- a/test/eventcomm-test.c +++ b/test/eventcomm-test.c @@ -135,6 +135,7 @@ test_read_hw_state(void) info.private = &private; info.fd = fd_read; + private.proto_data = EventProtoDataAlloc(); /* just the syn event */ reset_data(&hw, &comm); @@ -181,6 +182,8 @@ test_read_hw_state(void) /* the various buttons */ test_buttons(fd_write, &info, &hw, &comm); + + free(private.proto_data); } /** @@ -230,6 +233,8 @@ test_ignore_hw_state(void) info.private = &private; info.fd = fd_read; + private.proto_data = EventProtoDataAlloc(); + #define _assert_no_change(_type, _code) \ reset_data(&hw, &comm); \ ev.type = _type; \ @@ -273,6 +278,7 @@ test_ignore_hw_state(void) _assert_no_change(EV_KEY, i); } + free(private.proto_data); } int main (int argc, char **argv) |