[NTVDM]: Cast all the number-of-sectors computations to DWORD/ULONG to prevent potential overflows. Should fix a strange floppy read/write corruption I noticed.

svn path=/trunk/; revision=70424
This commit is contained in:
Hermès Bélusca-Maïto 2015-12-26 17:08:13 +00:00
parent c6ab198d15
commit 060e447a77
2 changed files with 5 additions and 5 deletions

View file

@ -608,8 +608,8 @@ VOID WINAPI BiosDiskService(LPWORD Stack)
setAH(0x03);
/* Number of 512-byte sectors in CX:DX */
NumSectors = DiskImage->DiskInfo.Cylinders * DiskImage->DiskInfo.Heads
* DiskImage->DiskInfo.Sectors;
NumSectors = (ULONG)((ULONG)DiskImage->DiskInfo.Cylinders * DiskImage->DiskInfo.Heads)
* DiskImage->DiskInfo.Sectors;
setCX(HIWORD(NumSectors));
setDX(LOWORD(NumSectors));
}

View file

@ -342,7 +342,7 @@ SeekDisk(IN PDISK_IMAGE DiskImage,
/* Set position */
// Compute the offset
FilePointer = ((Cylinder * DiskImage->DiskInfo.Heads + Head)
FilePointer = (DWORD)((DWORD)((DWORD)Cylinder * DiskImage->DiskInfo.Heads + Head)
* DiskImage->DiskInfo.Sectors + (Sector - 1))
* DiskImage->DiskInfo.SectorSize;
FilePointer = SetFilePointer(DiskImage->hDisk, FilePointer, NULL, FILE_BEGIN);
@ -373,7 +373,7 @@ ReadDisk(IN PDISK_IMAGE DiskImage,
if (Result != 0x00)
return Result;
BytesToRead = NumSectors * DiskImage->DiskInfo.SectorSize;
BytesToRead = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize;
// FIXME: Consider just looping around filling each time the buffer...
@ -434,7 +434,7 @@ WriteDisk(IN PDISK_IMAGE DiskImage,
if (Result != 0x00)
return Result;
BytesToWrite = NumSectors * DiskImage->DiskInfo.SectorSize;
BytesToWrite = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize;
// FIXME: Consider just looping around filling each time the buffer...