From 8eef1f89dced2f0511c57c4ad296ecd9b2d9bd1e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 11 Nov 2010 15:11:27 -0600 Subject: [PATCH] Fix some crashes by checking pointers before deref --- src/io_win.c | 2 ++ src/wiiuse.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/io_win.c b/src/io_win.c index 17fac36..3b27c41 100644 --- a/src/io_win.c +++ b/src/io_win.c @@ -144,6 +144,8 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { int i = 0; for (; i < wiimotes; ++i) { + if (!wm[i]) + continue; if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) ++connected; } diff --git a/src/wiiuse.c b/src/wiiuse.c index 8774b91..2632a42 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -505,8 +505,12 @@ void wiiuse_status(struct wiimote_t* wm) { */ struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) { int i = 0; + if (!wm) + return NULL; for (; i < wiimotes; ++i) { + if (!wm[i]) + continue; if (wm[i]->unid == unid) return wm[i]; }