Browse Source

Log: fixed a bug where we could index outside an array

when we first start up, num_existing_logs may be zero
master
Andrew Tridgell 13 years ago
parent
commit
ae1e1c940f
  1. 3
      ArduCopter/Log.pde
  2. 3
      ArduPlane/Log.pde

3
ArduCopter/Log.pde

@ -260,7 +260,8 @@ static void start_new_log() @@ -260,7 +260,8 @@ static void start_new_log()
end_pages[num_existing_logs - 1] = find_last_log_page(start_pages[num_existing_logs - 1]);
}
if((end_pages[num_existing_logs - 1] < 4095) && (num_existing_logs < MAX_NUM_LOGS /*50*/)) {
if(num_existing_logs == 0 ||
((end_pages[num_existing_logs - 1] < 4095) && (num_existing_logs < MAX_NUM_LOGS /*50*/))) {
if(num_existing_logs > 0)
start_pages[num_existing_logs] = end_pages[num_existing_logs - 1] + 1;

3
ArduPlane/Log.pde

@ -243,7 +243,8 @@ static void start_new_log(byte num_existing_logs) @@ -243,7 +243,8 @@ static void start_new_log(byte num_existing_logs)
end_pages[num_existing_logs - 1] = find_last_log_page(start_pages[num_existing_logs - 1]);
}
if(end_pages[num_existing_logs - 1] < 4095 && num_existing_logs < MAX_NUM_LOGS) {
if(num_existing_logs == 0 ||
(end_pages[num_existing_logs - 1] < 4095 && num_existing_logs < MAX_NUM_LOGS)) {
if(num_existing_logs > 0)
start_pages[num_existing_logs] = end_pages[num_existing_logs - 1] + 1;
else

Loading…
Cancel
Save