From 7b8413bbb95b9952537b81982ffc6f20cb9e8593 Mon Sep 17 00:00:00 2001 From: Ben Hymers Date: Fri, 13 Mar 2015 10:54:57 +0000 Subject: [PATCH] Protect against null pointer dereference in case GetProcAddress fails --- XInputInterface/GamePad.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/XInputInterface/GamePad.cpp b/XInputInterface/GamePad.cpp index 9f3e2e4..c708402 100644 --- a/XInputInterface/GamePad.cpp +++ b/XInputInterface/GamePad.cpp @@ -73,12 +73,22 @@ namespace DWORD XInputGamePadGetState(DWORD dwUserIndex, XINPUT_STATE* pState) { gXInputLoader.ensureLoaded(); - return gXInputLoader.mGetState(dwUserIndex, pState); + if(gXInputLoader.mGetState != NULL) + { + return gXInputLoader.mGetState(dwUserIndex, pState); + } + else + { + return ERROR_DEVICE_NOT_CONNECTED; + } } void XInputGamePadSetState(DWORD dwUserIndex, float leftMotor, float rightMotor) { gXInputLoader.ensureLoaded(); - XINPUT_VIBRATION vibration = { (int)(leftMotor * 65535), (int)(rightMotor * 65535) }; - gXInputLoader.mSetState(dwUserIndex, &vibration); -} \ No newline at end of file + if(gXInputLoader.mSetState != NULL) + { + XINPUT_VIBRATION vibration = { (int)(leftMotor * 65535), (int)(rightMotor * 65535) }; + gXInputLoader.mSetState(dwUserIndex, &vibration); + } +}