Skip to content

Commit

Permalink
Avoid malloc when converting to RAW
Browse files Browse the repository at this point in the history
  • Loading branch information
KrossX authored and refractionpcsx2 committed Jan 8, 2021
1 parent 511ceed commit 3a054b9
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions pcsx2/gui/MemoryCardFile.cpp
Expand Up @@ -99,28 +99,22 @@ bool ConvertNoECCtoRAW(wxString file_in, wxString file_out)
wxFFile fout(file_out, "wb");

if (fout.IsOpened()) {
u8 buffer[512];
size_t size = fin.Length();
u8* buffer = (u8*)malloc(size);

if (buffer) {
u8 empty[4] = { 0 };
fin.Read(buffer, size);

for (size_t i = 0; i < (size / 512); i++) {
u8* buf = &buffer[i * 512];
fout.Write(buf, 512);

for (int j = 0; j < 4; j++) {
u32 checksum = CalculateECC(&buf[j * 128]);
fout.Write(&checksum, 3);
}
for (size_t i = 0; i < (size / 512); i++) {
fin.Read(buffer, 512);
fout.Write(buffer, 512);

fout.Write(empty, 4);
for (int j = 0; j < 4; j++) {
u32 checksum = CalculateECC(&buffer[j * 128]);
fout.Write(&checksum, 3);
}

result = true;
free(buffer);
fout.Write("\0\0\0\0", 4);
}

result = true;
}
}

Expand Down

0 comments on commit 3a054b9

Please sign in to comment.