Fix crash when SD card is smaller than starting sector of scsi disk
authorMichael McMaster <michael@codesrc.com>
Sat, 29 Apr 2017 04:39:33 +0000 (14:39 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 29 Apr 2017 04:39:33 +0000 (14:39 +1000)
software/SCSI2SD/src/geometry.c
software/SCSI2SD/v4/SCSI2SD.cydsn/SCSI2SD.cyfit

index 0666b5a..c3c6bb7 100755 (executable)
@@ -28,7 +28,16 @@ uint32_t getScsiCapacity(
        uint32_t capacity =\r
                (sdDev.capacity - sdSectorStart) /\r
                        SDSectorsPerSCSISector(bytesPerSector);\r
        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
        {\r
                capacity = scsiSectors;\r
        }\r
index c2567cd..4ee1a97 100644 (file)
Binary files a/software/SCSI2SD/v4/SCSI2SD.cydsn/SCSI2SD.cyfit and b/software/SCSI2SD/v4/SCSI2SD.cydsn/SCSI2SD.cyfit differ