bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coreutils] coreutils-7.0 expr exposes long-standing bug in matlab s


From: Jim Meyering
Subject: Re: [coreutils] coreutils-7.0 expr exposes long-standing bug in matlab startup script
Date: Wed, 15 Oct 2008 08:49:48 +0200

Paul Eggert <address@hidden> wrote:
> Thanks for reporting that.  Clearly it's a matlab bug.  But just as
> clearly, many scripts out there assume that "expr -1 + 1" evaluates to
> zero.  We shouldn't break them unnecessarily.
>
> I looked at expr.c and have a somewhat radical suggestion.  Let's remove
> the --bignum and --no-bignum options, and go back to the old way of
> doing options.  That is, 'expr' should always use the bignum library if
> it's available.  The code can be greatly simplified if we assume the
> bignum case is the normal one, and supply some substitute routines when
> the bignum code is disabled at compile-time.
>
> One advantage of doing it this way is that on hosts without bignums, but
> with 32-bit long and 64-bit long long, the code will support 64-bit
> numbers.  In 7.0, the code supports only 32-bit numbers on such
> platforms, which is a regression from pre-7.0.
>
> Another advantage of doing it this way is that it shrinks the source
> code by about 25%.
>
> Here's a proposed patch to do that.  This change is a bit larger than
> it has to be compared to 7.0, because (to be conservative) when in doubt
> it does things the pre-7.0 way rather than the 7.0 way.  For example, it
> uses the same diagnostics as pre-7.0.

Hi Paul,

Wow.
Thanks for doing all that.
I haven't looked at it carefully, but do like the sound of it.

For reference, here's a small patch I just wrote that solves
at least some of the problems reported here, while retaining
the ability to use MP at run time.

diff --git a/src/expr.c b/src/expr.c
index dc41616..b7bec64 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -261,6 +261,7 @@ main (int argc, char **argv)
 {
   VALUE *v;
   int c;
+  int saved_optind;

   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -273,6 +274,7 @@ main (int argc, char **argv)

   /* The argument -0 should not result in an error message. */
   opterr = 0;
+  saved_optind = 1;

   while ((c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
     {
@@ -282,7 +284,7 @@ main (int argc, char **argv)
        */
       if ('?' == c)
        {
-         --optind;
+         optind = saved_optind;
          break;
        }
       else
@@ -305,6 +307,7 @@ main (int argc, char **argv)

            case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
          }
+      saved_optind = optind;
     }

   if (argc <= optind)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]