avoid some division by zero in hackish ways
authorderaadt <deraadt@openbsd.org>
Fri, 31 Jan 1997 11:59:05 +0000 (11:59 +0000)
committerderaadt <deraadt@openbsd.org>
Fri, 31 Jan 1997 11:59:05 +0000 (11:59 +0000)
sbin/fdisk/fdisk.c

index b720591..47004ee 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: fdisk.c,v 1.11 1997/01/27 21:57:36 rahnds Exp $       */
+/*     $OpenBSD: fdisk.c,v 1.12 1997/01/31 11:59:05 deraadt Exp $      */
 /*     $NetBSD: fdisk.c,v 1.11 1995/10/04 23:11:19 ghudson Exp $       */
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$OpenBSD: fdisk.c,v 1.11 1997/01/27 21:57:36 rahnds Exp $";
+static char rcsid[] = "$OpenBSD: fdisk.c,v 1.12 1997/01/31 11:59:05 deraadt Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -608,10 +608,16 @@ dos(sector, cylinderp, headp, sectorp)
 {
        int cylinder, head;
 
-       cylinder = sector / dos_cylindersectors;
+       if (dos_cylindersectors)
+               cylinder = sector / dos_cylindersectors;
+       else
+               cylinder = 0;
        sector -= cylinder * dos_cylindersectors;
 
-       head = sector / dos_sectors;
+       if (dos_sectors)
+               head = sector / dos_sectors;
+       else
+               head = 0;
        sector -= head * dos_sectors;
 
        *cylinderp = DOSCYL(cylinder);