Fix crash when SD card is smaller than starting sector of scsi disk
[SCSI2SD.git] / software / SCSI2SD / src / geometry.c
index 0666b5a..c3c6bb7 100755 (executable)
@@ -28,7 +28,16 @@ uint32_t getScsiCapacity(
        uint32_t capacity =\r
                (sdDev.capacity - sdSectorStart) /\r
                        SDSectorsPerSCSISector(bytesPerSector);\r
-       if (scsiSectors && (capacity > scsiSectors))\r
+\r
+       if (sdDev.capacity == 0)\r
+       {\r
+               capacity = 0;\r
+       }\r
+       else if (sdSectorStart >= sdDev.capacity)\r
+       {\r
+               capacity = 0;\r
+       }\r
+       else if (scsiSectors && (capacity > scsiSectors))\r
        {\r
                capacity = scsiSectors;\r
        }\r