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;
                              ^
This commit is contained in:
Marek Bel 2018-07-25 12:31:22 +02:00
parent e6dcbedf82
commit 98ba79e518
4 changed files with 26 additions and 24 deletions

View File

@ -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;

View File

@ -1373,8 +1373,7 @@ void temp_runaway_stop(bool isPreheat, bool isBed)
void disable_heater()
{
for(int i=0;i<EXTRUDERS;i++)
setTargetHotend(0,i);
setAllTargetHotends(0);
setTargetBed(0);
#if defined(TEMP_0_PIN) && TEMP_0_PIN > -1
target_temperature[0]=0;

View File

@ -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 (extruder<EXTRUDERS) target_temperature[extruder] = celsius;
}
static inline void setAllTargetHotends(const float &celsius)
{
for(int i=0;i<EXTRUDERS;i++) setTargetHotend(celsius,i);
}
FORCE_INLINE void setTargetBed(const float &celsius) {
target_temperature_bed = celsius;
};

View File

@ -1804,9 +1804,7 @@ void lcd_commands()
cancel_heatup = true;
setTargetBed(0);
#if !(defined (SNMM) || defined (SNMM_V2))
setTargetHotend(0, 0); //heating when changing filament for multicolor
setTargetHotend(0, 1);
setTargetHotend(0, 2);
setAllTargetHotends(0);
#endif
manage_heater();
custom_message = true;
@ -2036,9 +2034,7 @@ void lcd_preheat_flex()
void lcd_cooldown()
{
setTargetHotend0(0);
setTargetHotend1(0);
setTargetHotend2(0);
setAllTargetHotends(0);
setTargetBed(0);
fanSpeed = 0;
lcd_return_to_status();
@ -3126,7 +3122,7 @@ void lcd_adjust_z() {
bool lcd_wait_for_pinda(float temp) {
lcd_set_custom_characters_degree();
setTargetHotend(0, 0);
setAllTargetHotends(0);
setTargetBed(0);
LongTimer pinda_timeout;
pinda_timeout.start();
@ -3166,7 +3162,7 @@ void lcd_wait_for_heater() {
void lcd_wait_for_cool_down() {
lcd_set_custom_characters_degree();
setTargetHotend(0,0);
setAllTargetHotends(0);
setTargetBed(0);
while ((degHotend(0)>MAX_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