From e6d200cca173b605bc3cb57fa01903f115be9e8c Mon Sep 17 00:00:00 2001 From: cysimons Date: Wed, 22 Apr 2026 17:18:58 +0200 Subject: [PATCH] Fix null dereference in scheduler tick processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In trainprogram::scheduler(), bluetoothManager->device()->odometer() is called unconditionally at line 869. The null guard at line 626 does NOT protect this call — it enters an if-block that handles the 'not ready' case (Zwift API, OCR, etc.) but then falls through to line 869 regardless. If the device disconnects or is null at this point, the code crashes with a null pointer dereference. Fix: Add explicit null guard for both bluetoothManager and device() before the odometer() call. This ensures the scheduler exits safely if the device is unavailable. --- src/trainprogram.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/trainprogram.cpp b/src/trainprogram.cpp index ca91b306d9..5774f07776 100644 --- a/src/trainprogram.cpp +++ b/src/trainprogram.cpp @@ -866,6 +866,10 @@ void trainprogram::scheduler() { qDebug() << QStringLiteral("fixing jitter!") << seconds << ticks << currentTimerJitter; } + if (!bluetoothManager || !bluetoothManager->device()) { + return; + } + double odometerFromTheDevice = bluetoothManager->device()->odometer(); if(ticks < 0) {