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

when we first start up, num_existing_logs may be zero
This commit is contained in:
Andrew Tridgell 2011-11-07 22:24:03 +11:00
parent da800a295f
commit ae1e1c940f
2 changed files with 4 additions and 2 deletions

View File

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

View File

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