From 07d21b84a34068bb96fc56a52738ad1ce5233b93 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Tue, 11 Feb 2020 07:53:33 +0100 Subject: [PATCH] Refactor List operator[] to prevent compiler warnings. Prevents GCC compiler throwing: control reaches end of non-void function. Prevents Visual Studio throwing C4715: not all control paths return a value. --- core/list.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/core/list.h b/core/list.h index 0796410a84c1..6250cec59841 100644 --- a/core/list.h +++ b/core/list.h @@ -456,17 +456,12 @@ public: Element *I = front(); int c = 0; - while (I) { - - if (c == p_index) { - - return I->get(); - } + while (c < p_index) { I = I->next(); c++; } - CRASH_NOW(); // bug!! + return I->get(); } const T &operator[](int p_index) const { @@ -475,17 +470,12 @@ public: const Element *I = front(); int c = 0; - while (I) { - - if (c == p_index) { - - return I->get(); - } + while (c < p_index) { I = I->next(); c++; } - CRASH_NOW(); // bug!! + return I->get(); } void move_to_back(Element *p_I) {