GCMemcard: Avoid undefined behavior in the static Format().
This commit is contained in:
parent
87135db492
commit
131eb9107b
|
@ -1373,16 +1373,17 @@ bool GCMemcard::Format(u8* card_data, const CardFlashId& flash_id, u16 size_mbit
|
|||
{
|
||||
if (!card_data)
|
||||
return false;
|
||||
memset(card_data, 0xFF, BLOCK_SIZE * 3);
|
||||
memset(card_data + BLOCK_SIZE * 3, 0, BLOCK_SIZE * 2);
|
||||
|
||||
*((Header*)card_data) =
|
||||
Header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time);
|
||||
Header header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time);
|
||||
Directory dir;
|
||||
BlockAlloc bat(size_mbits);
|
||||
|
||||
std::memcpy(&card_data[BLOCK_SIZE * 0], &header, BLOCK_SIZE);
|
||||
std::memcpy(&card_data[BLOCK_SIZE * 1], &dir, BLOCK_SIZE);
|
||||
std::memcpy(&card_data[BLOCK_SIZE * 2], &dir, BLOCK_SIZE);
|
||||
std::memcpy(&card_data[BLOCK_SIZE * 3], &bat, BLOCK_SIZE);
|
||||
std::memcpy(&card_data[BLOCK_SIZE * 4], &bat, BLOCK_SIZE);
|
||||
|
||||
*((Directory*)(card_data + BLOCK_SIZE)) = Directory();
|
||||
*((Directory*)(card_data + BLOCK_SIZE * 2)) = Directory();
|
||||
*((BlockAlloc*)(card_data + BLOCK_SIZE * 3)) = BlockAlloc(size_mbits);
|
||||
*((BlockAlloc*)(card_data + BLOCK_SIZE * 4)) = BlockAlloc(size_mbits);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue