seq range infinite loop

Version:

coreutils-5.97 (fixed in 6.0)

How to reproduce?

coreutils-5.97/src/seq 9223372036854775807 9223372036854775808

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

9.22337e+18

Symptom:

Incorrect results. The correct behavior should be:

seq 9223372036854775807 9223372036854775808

9223372036854775807

9223372036854775808

Root cause:

The integer is too big and over the precision of “double”. The fix is to simply change the type of the the variables from “double” to “long double”...

static void

print_numbers (const char *fmt){

-  double i;

+  long double i;

  for (i = 0; /* empty */; i++)

   {

-    double x = first + i * step;

+    long double x = first + i * step;

    if (step < 0 ? x < last : last < x)

           --- ERROR: in the buggy case, x and

               last are always compared as SAME (over the precision)!!!

               So it will never break out...

         break;

    if (i)

         fputs (separator, stdout);

    printf (fmt, x);

  }

 if (i)

   fputs (terminator, stdout);

}

Is there Error Message?

No.

Can developers anticipate error and print an error msg?

It’s possible (although hard). They can check if the input number is over the precision limit, and print a warning msg for that case.

Can Errlog automatically insert an error msg?

No.