Number: 119
Title: Divide by zero in spline generation
Submitter: Nick Efthymiou
Date: 24 Mar 2002
Subsys: dot
Version: 1.8.2
System: *-*-*
Severity: minor
Problem:
a small number of layouts cause dot to receive a SIGFPE while calculating the route. The stack trace pointed to a calculation which only happens for very small numbers, which unfortunately includes zero.

I admit I don't understand why that division occurs only for numbers less than 1e-6; a divide by zero results in a Nan which is not useable for further calculations. Is it possible that the direction of the relational "<" in the if() statement is reversed?

Anyway, with the change shown in the attached patch file, the test completed without problems.
Fix:


*** route.c.orig	Thu Feb 28 13:35:33 2002
--- route.c	Fri Mar 22 01:22:08 2002
***************
*** 252,259 ****
      det0X = c[0][0] * x[1] - c[0][1] * x[0];
      detX1 = x[0] * c[1][1] - x[1] * c[0][1];
      if (ABS(det01) < 1e-6) {
!         scale0 = detX1 / det01;
!         scale3 = det0X / det01;
      }
      if (ABS (det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
          d01 = dist (inps[0], inps[inpn - 1]) / 3.0;
--- 252,261 ----
      det0X = c[0][0] * x[1] - c[0][1] * x[0];
      detX1 = x[0] * c[1][1] - x[1] * c[0][1];
      if (ABS(det01) < 1e-6) {
! 	if( det01 != 0.0 ){
!             scale0 = detX1 / det01;
!             scale3 = det0X / det01;
! 	}
      }
      if (ABS (det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
          d01 = dist (inps[0], inps[inpn - 1]) / 3.0;


Owner: north
Status: Fixed (2 April 2002)