Files
GoldenCheetah/unittests/Core/splineCrash/testSplineCrash.cpp
Magnus Gille 9bb90e3737 Fix crash safety issues: Unsafe signal connections and tree child access (#4761)
Systematically resolved 30 identified potential crash vectors and established automated regression testing to prevent strict reoccurrence.

Key Changes:
- Fixed 11 instances of unsafe `QObject::connect` calls (missing context object) in srd/Charts/AgendaWindow.cpp, FixSpikes.cpp, src/FileIO/FixSpikes.cpp, src/Gui/Agenda.cpp, src/Gui/BatchProcessingDialog.cpp, and src/Gui/IconManager.cpp. This prevents crashes caused by signals firing after the receiver has been destroyed.
- Fixed 19 instances of unsafe `QTreeWidgetItem` child access in src/Charts/LTMChartParser.cpp, src/Gui/ColorButton.cpp, src/Gui/AthletePages.cpp, and src/Gui/Pages.cpp by adding defensive `nullptr` checks before dereferencing.
- Added Python detection scripts util/check_unsafe_connects.py and util/check_unsafe_tree_child.py to statically analyze the codebase for these specific unsafe patterns.
- Integrated detection scripts into the regression test suite under `unittests/Core/signalSafety`, verifying the fixes and enforcing a strict zero-tolerance policy for future regressions.
- Added `testSplineCrash` to cover edge cases with empty spline lookups.
2025-12-17 13:52:38 -03:00

21 lines
448 B
C++

#include <QTest>
#include <QObject>
#include "Core/SplineLookup.h"
class TestSplineCrash : public QObject
{
Q_OBJECT
private slots:
void testEmptySpline() {
SplineLookup spline;
// Verify it is empty (default state)
// Calling valueY(10.0) should return 10.0 and NOT crash.
double val = spline.valueY(10.0);
QCOMPARE(val, 10.0);
}
};
QTEST_MAIN(TestSplineCrash)
#include "testSplineCrash.moc"