Skip to content

Commit

Permalink
initiator: Fix overflow in percentage calculation (#404)
Browse files Browse the repository at this point in the history
When drive size was larger than 8 GB, LED indicator and logged percentage
would reset to 0 midway through the transfer.
  • Loading branch information
PetteriAimonen committed Sep 5, 2024
1 parent 6ac3765 commit 33f76eb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ZuluSCSI_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void scsiInitiatorUpdateLed()
// Update status indicator, the led blinks every 5 seconds and is on the longer the more data has been transferred
const int period = 256;
int phase = (millis() % period);
int duty = g_initiator_state.sectors_done * period / g_initiator_state.sectorcount;
int duty = (int64_t)g_initiator_state.sectors_done * period / g_initiator_state.sectorcount;

// Minimum and maximum time to verify that the blink is visible
if (duty < 50) duty = 50;
Expand Down Expand Up @@ -532,7 +532,7 @@ void scsiInitiatorMainLoop()
logmsg("SCSI read succeeded, sectors done: ",
(int)g_initiator_state.sectors_done, " / ", (int)g_initiator_state.sectorcount,
" speed ", speed_kbps, " kB/s - ",
(int)(100 * g_initiator_state.sectors_done / g_initiator_state.sectorcount), "%");
(int)(100 * (int64_t)g_initiator_state.sectors_done / g_initiator_state.sectorcount), "%");
}
}
}
Expand Down

0 comments on commit 33f76eb

Please sign in to comment.