bug-bash
[Top][All Lists]
Advanced

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

Re: Bash arithmetic doesn't give error message on wrap.


From: Richard Neill
Subject: Re: Bash arithmetic doesn't give error message on wrap.
Date: Mon, 30 Apr 2007 00:16:09 +0100
User-agent: Thunderbird 1.5.0.10 (X11/20070403)



Bob Proulx wrote:
Richard Neill wrote:
 b)Consistent with other cases, where bash does give warnings. For example:

$ X=$((3+078))
bash: 3+078: value too great for base (error token is "078")
$ echo $?
1

That is not really a comparable case.  The problem there is that the
leading zero specifies an octal constant and the 8 cannot be converted
to octal.  The "3+" part is just a distraction.

  echo $((08))
  bash: 08: value too great for base (error token is "08")

Bob


Are you sure this isn't comparable? After all, in both cases, the user has submitted something to which bash cannot give a sensible answer. In the integer-overflow case, bash simply returns the wrong answer, with no warning. But in the octal case, bash (quite correctly, and helpfully) prints a warning.

If bash were to be consistent, then it should display no error message in the case of $((3+078)); it should either "Do what I mean" [evaluate 3 + 078 as 0103, treating 78 as 7 *8 + 8], or "Do something daft" [eg evaluate as 073 (treating 8 as an integer-overflow in the units place, which is not checked for)]

There's obviously an advantage to the user in being warned when an integer overflow occurs; is there any possible downside (apart from a couple of extra lines of code?

Richard




reply via email to

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