From 98ba79e5189d8178d6f2493a9e2455f659436d64 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 25 Jul 2018 12:31:22 +0200 Subject: [PATCH] Fix out of array bounds access. Manifested as compiler warnings: In file included from sketch/Marlin_main.cpp:67:0: sketch/temperature.h: In function 'bool gcode_M45(bool, int8_t)': sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ sketch/temperature.h: In function 'void long_pause()': sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ sketch/temperature.h: In function 'void process_commands()': sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ sketch/temperature.h:142:30: warning: array subscript is above array bounds [-Warray-bounds] target_temperature[extruder] = celsius; ^ --- Firmware/Marlin_main.cpp | 25 +++++++++++-------------- Firmware/temperature.cpp | 3 +-- Firmware/temperature.h | 10 ++++++++++ Firmware/ultralcd.cpp | 12 ++++-------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 34a12101..5932df03 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1780,7 +1780,7 @@ int chunkHead = 0; void serial_read_stream() { - setTargetHotend(0, 0); + setAllTargetHotends(0); setTargetBed(0); lcd_clear(); @@ -2874,9 +2874,7 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) if (!onlyZ) { setTargetBed(0); - setTargetHotend(0, 0); - setTargetHotend(0, 1); - setTargetHotend(0, 2); + setAllTargetHotends(0); adjust_bed_reset(); //reset bed level correction } @@ -5262,7 +5260,10 @@ Sigma_Exit: if(setTargetedHotend(104)){ break; } - if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder); + if (code_seen('S')) + { + setTargetHotendSafe(code_value(), tmp_extruder); + } setWatch(); break; case 112: // M112 -Emergency Stop @@ -5375,10 +5376,10 @@ Sigma_Exit: autotemp_enabled=false; #endif if (code_seen('S')) { - setTargetHotend(code_value(), tmp_extruder); + setTargetHotendSafe(code_value(), tmp_extruder); CooldownNoWait = true; } else if (code_seen('R')) { - setTargetHotend(code_value(), tmp_extruder); + setTargetHotendSafe(code_value(), tmp_extruder); CooldownNoWait = false; } #ifdef AUTOTEMP @@ -6366,9 +6367,7 @@ bFirst=false; if (millis() > waiting_start_time + (unsigned long)M600_TIMEOUT * 1000) { lcd_display_message_fullscreen_P(_i("Press knob to preheat nozzle and continue."));////MSG_PRESS_TO_PREHEAT c=20 r=4 wait_for_user_state = 1; - setTargetHotend(0, 0); - setTargetHotend(0, 1); - setTargetHotend(0, 2); + setAllTargetHotends(0); st_synchronize(); disable_e0(); disable_e1(); @@ -7508,7 +7507,7 @@ static void handleSafetyTimer() else if (safetyTimer.expired(safetytimer_inactive_time)) { setTargetBed(0); - setTargetHotend(0, 0); + setAllTargetHotends(0); lcd_show_fullscreen_message_and_wait_P(_i("Heating disabled by safety timer."));////MSG_BED_HEATING_SAFETY_DISABLED c=0 r=0 } } @@ -8313,9 +8312,7 @@ void long_pause() //long pause print plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); //set nozzle target temperature to 0 - setTargetHotend(0, 0); - setTargetHotend(0, 1); - setTargetHotend(0, 2); + setAllTargetHotends(0); //Move XY to side current_position[X_AXIS] = X_PAUSE_POS; diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 15ee34da..166b108c 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1373,8 +1373,7 @@ void temp_runaway_stop(bool isPreheat, bool isBed) void disable_heater() { - for(int i=0;i -1 target_temperature[0]=0; diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 462412d3..0633158c 100644 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -142,6 +142,16 @@ FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { target_temperature[extruder] = celsius; }; +static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder) +{ + if (extruderMAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) { lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3