diff -Nru stable/libparted/disk_dos.c test-noFParith/libparted/disk_dos.c
--- stable/libparted/disk_dos.c	2005-07-19 23:41:25.000000000 +0200
+++ test-noFParith/libparted/disk_dos.c	2005-08-01 14:50:52.415312608 +0200
@@ -488,6 +488,7 @@
 	RawCHS* end_chs;
 	PedSector c, h, s, a, a_;	/* start */
 	PedSector C, H, S, A, A_;	/* end */
+	PedSector dont_overflow, denum;
 	PedSector cyl_size, head_size;
 	PedSector cylinders, heads, sectors;
 
@@ -532,53 +533,55 @@
 	if (C == 0)
 		return 0;
 
-	/* STEP ONE: find cyl_size */
-	if (h == 0 && c > 0) {
-		/* If the matrix looks like this
-		 * 
-		 * [ c 0 | a_]
-		 * [ C H | A_],
-		 *
-		 * then the cylinder size is just a_ / c;
-		 */
-		cyl_size = a_ / c;
-	} else if (h > 0) {
-		/* If the matrix looks like
-		 *
-		 * [ c h | a_]
-		 * [ C H | A_]
-		 *
-		 * with h > 0, then we can do R2 <- R2 - H/h R1 to get
-		 *
-		 * [ c h | a_ ]
-		 * [ X 0 | Y  ].
-		 *
-		 * Then, cyl_size = Y / X.  Note that H/h, X and Y need not be
-		 * integers.
-		 */
-		float ratio = 1.0 * H / h;
-		float X = C - ratio * c;
-		float Y = A_ - ratio * a_;
-		if (-0.001 < X && X < 0.001)
-			return 0;
-		cyl_size = Y / X;
-	} else {
-		/* h == 0 && c == 0: not enough information */
+	/* Calculate the maximum number that can be multiplied by
+	 * any head count without overflowing a PedSector
+	 * 2^8 = 256, 8 bits + 1(sign bit) = 9
+	 */
+	dont_overflow = 1;
+	dont_overflow <<= (8*sizeof(dont_overflow)) - 9;
+	dont_overflow--;
+
+	if (a_ > dont_overflow || A_ > dont_overflow)
+		return 0;
+
+	/* The matrix is solved by :
+	 *
+	 * [ c h | a_]			R1
+	 * [ C H | A_]			R2
+	 *
+	 * (cH - Ch) cyl_size = a_H - A_h		H R1 - h R2
+	 * => (if cH - Ch != 0) cyl_size = (a_H - A_h) / (cH - Ch)
+	 *
+	 * (Hc - hC) head_size = A_c - a_C		c R2 - C R1
+	 * => (if cH - Ch != 0) head_size = (A_c - a_C) / (cH - Ch)
+	 *
+	 *   But this calculation of head_size would need
+	 *   not overflowing A_c or a_C
+	 *   So substitution is use instead, to minimize dimension
+	 *   of temporary results :
+	 *
+	 * If h != 0 : head_size = ( a_ - c cyl_size ) / h
+	 * If H != 0 : head_size = ( A_ - C cyl_size ) / H
+	 *
+	 */
+	denum = c * H - C * h;
+	if (denum == 0)
+		return 0;
+
+	cyl_size = (a_*H - A_*h) / denum;
+	/* Check for non integer result */
+	if (cyl_size * denum != a_*H - A_*h)
 		return 0;
-	}
 
 	PED_ASSERT (cyl_size > 0, return 0);
  	PED_ASSERT (cyl_size <= 255 * 63, return 0);
 
-	/* STEP TWO: find head_size */
-	if (h > 0) {
-		head_size = (a_ - c * cyl_size) / h;
-	} else if (H > 0) {
-		head_size = (A_ - C * cyl_size) / H;
-	} else {
-		/* not enough information */
-		return 0;
-	}
+	if (h > 0)
+		head_size = ( a_ - c * cyl_size ) / h;
+	else if (H > 0)
+		head_size = ( A_ - C * cyl_size ) / H;
+	else /* should not happen because denum != 0 */
+		PED_ASSERT (0, return 0);
 
 	PED_ASSERT (head_size > 0, return 0);
 	PED_ASSERT (head_size <= 63, return 0);
