From 4fd89b0b8f0b01412f15384acf7fb6af38b4626f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sun, 22 Jan 2017 14:15:12 +0100 Subject: [PATCH 1/4] Fixed compilation warning on Mac IOHIDManagerRegisterDeviceMatchingCallback must not be called with nullptr as the second argument. --- src/Cockpit/NavDisplay.cxx | 2 +- src/Input/FGMacOSXEventInput.cxx | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Cockpit/NavDisplay.cxx b/src/Cockpit/NavDisplay.cxx index d2182eaee..504cf97f5 100644 --- a/src/Cockpit/NavDisplay.cxx +++ b/src/Cockpit/NavDisplay.cxx @@ -183,7 +183,7 @@ private: class SymbolRule { public: - SymbolRule() + SymbolRule() : enabled(false) { } diff --git a/src/Input/FGMacOSXEventInput.cxx b/src/Input/FGMacOSXEventInput.cxx index eaf451108..517322e17 100644 --- a/src/Input/FGMacOSXEventInput.cxx +++ b/src/Input/FGMacOSXEventInput.cxx @@ -229,9 +229,6 @@ void FGMacOSXEventInput::shutdown() { FGEventInput::shutdown(); - IOHIDManagerRegisterDeviceMatchingCallback(d->hidManager, nullptr, nullptr); - IOHIDManagerRegisterDeviceRemovalCallback(d->hidManager, nullptr, nullptr); - IOHIDManagerClose(d->hidManager, kIOHIDOptionsTypeNone); IOHIDManagerUnscheduleFromRunLoop(d->hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); CFRelease(d->hidManager); From f71c20600a9076049707d566833a87b0d742cbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sun, 22 Jan 2017 14:16:54 +0100 Subject: [PATCH 2/4] Fixed erroreous reference to array instead of its element net->master_{bat,alt} are arrays, but were mistakenly used as values. This correctly generated a compilation warning. --- src/Network/native_ctrls.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Network/native_ctrls.cxx b/src/Network/native_ctrls.cxx index 81ad1866f..61cc4ffef 100644 --- a/src/Network/native_ctrls.cxx +++ b/src/Network/native_ctrls.cxx @@ -428,8 +428,8 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes, // node->setDoubleValue( net->brake_right ); node = fgGetNode( "/controls/switches", true ); - node->setBoolValue( "master-bat", net->master_bat != 0 ); - node->setBoolValue( "master-alt", net->master_alt != 0 ); + node->setBoolValue( "master-bat", net->master_bat[0] != 0 ); + node->setBoolValue( "master-alt", net->master_alt[0] != 0 ); node->setBoolValue( "master-avionics", net->master_avionics > 0 ); node = fgGetNode( "/environment", true ); From d401a50e0a13710561e3fa2129c53da0a9b6c4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sat, 25 Feb 2017 14:42:40 +0100 Subject: [PATCH 3/4] Fix crash on Mac OS X when FG does not finish input init --- src/Input/FGMacOSXEventInput.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Input/FGMacOSXEventInput.cxx b/src/Input/FGMacOSXEventInput.cxx index 517322e17..b8d7168fe 100644 --- a/src/Input/FGMacOSXEventInput.cxx +++ b/src/Input/FGMacOSXEventInput.cxx @@ -229,9 +229,11 @@ void FGMacOSXEventInput::shutdown() { FGEventInput::shutdown(); - IOHIDManagerClose(d->hidManager, kIOHIDOptionsTypeNone); - IOHIDManagerUnscheduleFromRunLoop(d->hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - CFRelease(d->hidManager); + if (d->hidManager) { + IOHIDManagerClose(d->hidManager, kIOHIDOptionsTypeNone); + IOHIDManagerUnscheduleFromRunLoop(d->hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + CFRelease(d->hidManager); + } } // From e1668a2919a93a7ce4390fc29661b0b31129be48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sat, 25 Feb 2017 14:48:54 +0100 Subject: [PATCH 4/4] Fixed a number of use-after-free bugs with FGPositioneds These were due to converting FGPositionedRef to FGPositioned* and then again packing the pointer into another ref-counted FGPositionedRef. --- src/Navaids/NavDataCache.cxx | 6 +++--- src/Navaids/positioned.cxx | 4 ++-- src/Navaids/positioned.hxx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index efe600e76..e40894246 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -1706,7 +1706,7 @@ FGPositionedRef NavDataCache::loadById(PositionedID rowid) } sqlite3_int64 aptId; - FGPositioned* pos = d->loadById(rowid, aptId); + FGPositionedRef pos = d->loadById(rowid, aptId); d->cache.insert(it, PositionedCache::value_type(rowid, pos)); d->cacheMisses++; @@ -1933,7 +1933,7 @@ FGPositionedRef NavDataCache::findClosestWithIdent( const string& aIdent, FGPositionedRef result; while (d->stepSelect(d->findClosestWithIdent)) { - FGPositioned* pos = loadById(sqlite3_column_int64(d->findClosestWithIdent, 0)); + FGPositionedRef pos = loadById(sqlite3_column_int64(d->findClosestWithIdent, 0)); if (aFilter && !aFilter->pass(pos)) { continue; } @@ -2073,7 +2073,7 @@ NavDataCache::findCommByFreq(int freqKhz, const SGGeod& aPos, FGPositioned::Filt FGPositionedRef result; while (d->execSelect(d->findCommByFreq)) { - FGPositioned* p = loadById(sqlite3_column_int64(d->findCommByFreq, 0)); + FGPositionedRef p = loadById(sqlite3_column_int64(d->findCommByFreq, 0)); if (aFilter && !aFilter->pass(p)) { continue; } diff --git a/src/Navaids/positioned.cxx b/src/Navaids/positioned.cxx index 689259e89..acfcedf42 100644 --- a/src/Navaids/positioned.cxx +++ b/src/Navaids/positioned.cxx @@ -85,7 +85,7 @@ FGPositioned::~FGPositioned() { } -FGPositioned* +FGPositionedRef FGPositioned::createUserWaypoint(const std::string& aIdent, const SGGeod& aPos) { NavDataCache* cache = NavDataCache::instance(); @@ -93,7 +93,7 @@ FGPositioned::createUserWaypoint(const std::string& aIdent, const SGGeod& aPos) FGPositionedList existing = cache->findAllWithIdent(aIdent, &filter, true); if (!existing.empty()) { SG_LOG(SG_NAVAID, SG_WARN, "attempt to insert duplicate WAYPOINT:" << aIdent); - return existing.front().ptr(); + return existing.front(); } PositionedID id = cache->createPOI(WAYPOINT, aIdent, aPos); diff --git a/src/Navaids/positioned.hxx b/src/Navaids/positioned.hxx index 5187f8ddb..3be97f74a 100644 --- a/src/Navaids/positioned.hxx +++ b/src/Navaids/positioned.hxx @@ -269,7 +269,7 @@ public: */ static const char* nameForType(Type aTy); - static FGPositioned* createUserWaypoint(const std::string& aIdent, const SGGeod& aPos); + static FGPositionedRef createUserWaypoint(const std::string& aIdent, const SGGeod& aPos); static bool deleteUserWaypoint(const std::string& aIdent); protected: friend class flightgear::NavDataCache;