From 42dc9e36627b44b4c49e706210a8b099016c1377 Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 8 Oct 2019 01:26:35 -0400 Subject: [PATCH] fancy C++ s/NULL/nullptr/ --- firmware/controllers/actuators/aux_pid.cpp | 2 +- firmware/controllers/actuators/lcd_controller.cpp | 2 +- firmware/controllers/algo/accel_enrichment.cpp | 2 +- firmware/controllers/algo/event_registry.h | 4 ++-- firmware/controllers/algo/lcd_menu_tree.cpp | 11 ++++------- firmware/controllers/algo/lcd_menu_tree.h | 6 +++--- firmware/controllers/core/efi_wave.cpp | 2 -- firmware/controllers/core/efi_wave.h | 4 ++-- firmware/controllers/core/fsio_core.cpp | 10 +++++----- firmware/controllers/injector_central.cpp | 2 +- firmware/controllers/math/pid_auto_tune.cpp | 2 +- firmware/controllers/scheduling/event_queue.cpp | 2 +- firmware/controllers/sensors/thermistors.cpp | 2 +- firmware/controllers/trigger/trigger_decoder.cpp | 2 +- firmware/development/wave_analyzer.cpp | 4 ++-- firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp | 2 +- firmware/util/datalogging.cpp | 5 ----- firmware/util/datalogging.h | 10 +++++----- unit_tests/engine_test_helper.cpp | 2 +- 19 files changed, 33 insertions(+), 43 deletions(-) diff --git a/firmware/controllers/actuators/aux_pid.cpp b/firmware/controllers/actuators/aux_pid.cpp index 4f4ce1a5a1..9763ae5197 100644 --- a/firmware/controllers/actuators/aux_pid.cpp +++ b/firmware/controllers/actuators/aux_pid.cpp @@ -110,7 +110,7 @@ public: private: Pid auxPid; int index = 0; - ValueProvider3D *table = NULL; + ValueProvider3D *table = nullptr; }; static AuxPidController instances[AUX_PID_COUNT]; diff --git a/firmware/controllers/actuators/lcd_controller.cpp b/firmware/controllers/actuators/lcd_controller.cpp index 7c84075c98..30d4de6531 100644 --- a/firmware/controllers/actuators/lcd_controller.cpp +++ b/firmware/controllers/actuators/lcd_controller.cpp @@ -325,7 +325,7 @@ static void fillWithSpaces(void) { void updateHD44780lcd(void) { MenuItem *p = tree.topVisible; int screenY = 0; - for (; screenY < tree.linesCount && p != NULL; screenY++) { + for (; screenY < tree.linesCount && p != nullptr; screenY++) { lcd_HD44780_set_position(screenY, 0); char firstChar; if (p == tree.current) { diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index c2eb5e94e9..dceae51330 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -38,7 +38,7 @@ EXTERN_ENGINE tps_tps_Map3D_t tpsTpsMap("tpsTps"); -static Logging *logger = NULL; +static Logging *logger = nullptr; WallFuel::WallFuel() { resetWF(); diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index 49085bf501..f565a379c3 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -45,7 +45,7 @@ public: uint32_t startOfDwell; event_trigger_position_s dwellPosition; event_trigger_position_s sparkPosition; - IgnitionEvent *next = NULL; + IgnitionEvent *next = nullptr; /** * @see globalSparkIdCoutner */ @@ -54,7 +54,7 @@ public: * [0, specs.cylindersCount) */ int cylinderIndex = 0; - char *name = NULL; + char *name = nullptr; #if EFI_UNIT_TEST Engine *engine; #endif diff --git a/firmware/controllers/algo/lcd_menu_tree.cpp b/firmware/controllers/algo/lcd_menu_tree.cpp index 58fa425498..1572e0c7f6 100644 --- a/firmware/controllers/algo/lcd_menu_tree.cpp +++ b/firmware/controllers/algo/lcd_menu_tree.cpp @@ -11,9 +11,6 @@ MenuTree::MenuTree(MenuItem *root) { this->root = root; - current = NULL; - linesCount = 0; - topVisible = NULL; } void MenuTree::init(MenuItem *first, int linesCount) { @@ -74,10 +71,10 @@ void MenuItem::baseConstructor(MenuItem * parent, lcd_line_e lcdLine, const char this->text = text; this->callback = callback; - firstChild = NULL; - lastChild = NULL; - topOfTheList = NULL; - next = NULL; + firstChild = nullptr; + lastChild = nullptr; + topOfTheList = nullptr; + next = nullptr; index = 0; // root element has NULL parent diff --git a/firmware/controllers/algo/lcd_menu_tree.h b/firmware/controllers/algo/lcd_menu_tree.h index 34e65c08a1..2a8e208ec0 100644 --- a/firmware/controllers/algo/lcd_menu_tree.h +++ b/firmware/controllers/algo/lcd_menu_tree.h @@ -69,9 +69,9 @@ public: void init(MenuItem *first, int linesCount); MenuItem *root; - int linesCount; - MenuItem *current; - MenuItem *topVisible; + int linesCount = 0; + MenuItem *current = nullptr; + MenuItem *topVisible = nullptr; }; diff --git a/firmware/controllers/core/efi_wave.cpp b/firmware/controllers/core/efi_wave.cpp index 4c2252fd3f..7d54d76918 100644 --- a/firmware/controllers/core/efi_wave.cpp +++ b/firmware/controllers/core/efi_wave.cpp @@ -33,8 +33,6 @@ void SingleWave::setState(int switchIndex, pin_state_t state) { } MultiWave::MultiWave() { - channels = NULL; - switchTimes = NULL; reset(); } diff --git a/firmware/controllers/core/efi_wave.h b/firmware/controllers/core/efi_wave.h index 4761a15218..55d055a2ab 100644 --- a/firmware/controllers/core/efi_wave.h +++ b/firmware/controllers/core/efi_wave.h @@ -77,13 +77,13 @@ public: * Number of signal channels */ int waveCount; - SingleWave *channels; + SingleWave *channels = nullptr; //private: /** * values in the (0..1] range which refer to points within the period at at which pin state should be changed * So, in the simplest case we turn pin off at 0.3 and turn it on at 1 - that would give us a 70% duty cycle PWM */ - float *switchTimes; + float *switchTimes = nullptr; }; #endif /* EFI_WAVE_H_ */ diff --git a/firmware/controllers/core/fsio_core.cpp b/firmware/controllers/core/fsio_core.cpp index 8b455c2cfc..be7033196d 100644 --- a/firmware/controllers/core/fsio_core.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -31,7 +31,7 @@ static fsio8_Map3D_u8t * fsio8t_tables[] = {NULL, NULL, &fsioTable2, &fsioTable3 EXTERN_ENGINE; -LENameOrdinalPair * LE_FIRST = NULL; +LENameOrdinalPair * LE_FIRST = nullptr; /** * the main point of these static fields is that their constructor would register @@ -72,7 +72,7 @@ LEElement::LEElement() { void LEElement::clear() { action = LE_UNDEFINED; - next = NULL; + next = nullptr; fValue = NAN; iValue = 0; } @@ -91,7 +91,7 @@ LECalculator::LECalculator() { } void LECalculator::reset() { - first = NULL; + first = nullptr; stack.reset(); currentCalculationLogPosition = 0; memset(calcLogAction, 0, sizeof(calcLogAction)); @@ -405,8 +405,8 @@ static char parsingBuffer[64]; LEElement *LEElementPool::parseExpression(const char * line) { - LEElement *first = NULL; - LEElement *last = NULL; + LEElement *first = nullptr; + LEElement *last = nullptr; while (true) { line = getNextToken(line, parsingBuffer, sizeof(parsingBuffer)); diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 35383550c6..335ebb29e9 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -255,7 +255,7 @@ void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) { scheduleMsg(logger, "unregistering %s", hwPortname(oldPin)); #if EFI_GPIO_HARDWARE brain_pin_markUnused(oldPin); - port = NULL; + port = nullptr; #endif /* EFI_GPIO_HARDWARE */ } } diff --git a/firmware/controllers/math/pid_auto_tune.cpp b/firmware/controllers/math/pid_auto_tune.cpp index 895fda4014..ac4c9142fe 100644 --- a/firmware/controllers/math/pid_auto_tune.cpp +++ b/firmware/controllers/math/pid_auto_tune.cpp @@ -64,7 +64,7 @@ void PID_AutoTune::reset() { memset(lastPeaks, 0, sizeof(lastPeaks)); memset(lastInputs, 0, sizeof(lastInputs)); - logger = NULL; + logger = nullptr; input = output = 0; SetLookbackSec(10); diff --git a/firmware/controllers/scheduling/event_queue.cpp b/firmware/controllers/scheduling/event_queue.cpp index c5dff86d73..4bc9bcd75d 100644 --- a/firmware/controllers/scheduling/event_queue.cpp +++ b/firmware/controllers/scheduling/event_queue.cpp @@ -152,7 +152,7 @@ int EventQueue::executeAll(efitime_t now) { lastInExecutionList->next = current; lastInExecutionList = current; } - current->next = NULL; + current->next = nullptr; } else { /** * The list is sorted. Once we find one action in the future, all the remaining ones diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 2332b1d1d3..72b77fa509 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -27,7 +27,7 @@ EXTERN_ENGINE ; -static Logging *logger = NULL; +static Logging *logger = nullptr; /** * http://en.wikipedia.org/wiki/Voltage_divider diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 023f50797d..e948ddce88 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -58,7 +58,7 @@ void TriggerState::setShaftSynchronized(bool value) { } void TriggerState::resetTriggerState() { - triggerCycleCallback = NULL; + triggerCycleCallback = nullptr; setShaftSynchronized(false); toothed_previous_time = 0; diff --git a/firmware/development/wave_analyzer.cpp b/firmware/development/wave_analyzer.cpp index 43eebf3f84..e375234541 100644 --- a/firmware/development/wave_analyzer.cpp +++ b/firmware/development/wave_analyzer.cpp @@ -143,9 +143,9 @@ static void initWave(const char *name, int index) { #endif WaveReader::WaveReader() { - hw = NULL; + hw = nullptr; last_wave_high_widthUs = 0; - name = NULL; + name = nullptr; fallEventCounter = riseEventCounter = 0; currentRevolutionCounter = 0; prevTotalOnTimeUs = 0; diff --git a/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp b/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp index ebc20ac102..8249294693 100644 --- a/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp +++ b/firmware/hw_layer/ports/stm32/stm32f4/mpu_util.cpp @@ -340,7 +340,7 @@ void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, } void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) { - spiConfig->end_cb = NULL; + spiConfig->end_cb = nullptr; ioportid_t port = getHwPort("spi", csPin); ioportmask_t pin = getHwPin("spi", csPin); spiConfig->ssport = port; diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index b9a9bdd5f8..46f05a9bcf 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -296,11 +296,6 @@ void Logging::appendPrintf(const char *fmt, ...) { #endif /* ! EFI_UNIT_TEST */ Logging::Logging() { - name = NULL; - buffer = NULL; - linePointer = NULL; - bufferSize = 0; - isInitialized = false; } Logging::Logging(char const *name, char *buffer, int bufferSize) : Logging(){ diff --git a/firmware/util/datalogging.h b/firmware/util/datalogging.h index 2987b0a728..b12584f972 100644 --- a/firmware/util/datalogging.h +++ b/firmware/util/datalogging.h @@ -25,21 +25,21 @@ public: void append(const char *text); void appendFast(const char *text); void appendPrintf(const char *fmt, ...); - const char *name; + const char *name = nullptr; char SMALL_BUFFER[40]; /** * Zero-terminated buffer of pending debug message * * Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER */ - char *buffer; + char *buffer = nullptr; /** * This pointer is always pointing at the position within the buffer into which next * write operation would append additional data */ - char *linePointer; - int bufferSize; - volatile bool isInitialized; + char *linePointer = nullptr; + int bufferSize = 0; + volatile bool isInitialized = false; }; class LoggingWithStorage : public Logging { diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 7e7a3619df..6fb93e48df 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -128,7 +128,7 @@ void EngineTestHelper::fireTriggerEvents2(int count, float durationMs) { void EngineTestHelper::clearQueue() { engine.executor.executeAll(99999999); // this is needed to clear 'isScheduled' flag ASSERT_EQ( 0, engine.executor.size()) << "Failed to clearQueue"; - engine.iHead = NULL; // let's drop whatever was scheduled just to start from a clean state + engine.ignitionEventsHead = nullptr; // let's drop whatever was scheduled just to start from a clean state } int EngineTestHelper::executeActions() {