Initialize ffd to -1 in the constructor otherwise many checks may fail

afterwards, and BJoystick won't work.
Also reset it to -1 in the destructor for symmetry.
Found by Carwyn Jones. Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40900 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2011-03-10 08:21:44 +00:00
parent 0a3b9e75e0
commit aac111dc76
+9 -4
View File
@@ -49,6 +49,7 @@ LOG(const char *fmt, ...)
BJoystick::BJoystick() BJoystick::BJoystick()
: :
fBeBoxMode(false), fBeBoxMode(false),
ffd(-1),
fDevices(new BList), fDevices(new BList),
fJoystickInfo(new _joystick_info()) fJoystickInfo(new _joystick_info())
{ {
@@ -61,8 +62,10 @@ BJoystick::BJoystick()
BJoystick::~BJoystick() BJoystick::~BJoystick()
{ {
if (ffd >= 0) if (ffd >= 0) {
close(ffd); close(ffd);
ffd = -1;
}
for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) { for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) {
free(fDevices->RemoveItem(count)); free(fDevices->RemoveItem(count));
@@ -132,17 +135,18 @@ void
BJoystick::Close(void) BJoystick::Close(void)
{ {
CALLED(); CALLED();
if (ffd >= 0) if (ffd >= 0) {
close(ffd); close(ffd);
ffd = -1; ffd = -1;
} }
}
void void
BJoystick::ScanDevices(bool use_disabled) BJoystick::ScanDevices(bool useDisabled)
{ {
CALLED(); CALLED();
if (use_disabled) { if (useDisabled) {
_BJoystickTweaker temp(*this); _BJoystickTweaker temp(*this);
temp.scan_including_disabled(); temp.scan_including_disabled();
} }
@@ -228,6 +232,7 @@ BJoystick::CountButtons()
return fJoystickInfo->num_buttons; return fJoystickInfo->num_buttons;
} }
status_t status_t
BJoystick::GetControllerModule(BString *out_name) BJoystick::GetControllerModule(BString *out_name)
{ {