Op 05-03-18 om 22:41 schreef Harald van Dijk: > On 3/5/18 1:32 AM, Martijn Dekker wrote: >> dash compiled on Mac OS X (macOS) and FreeBSD manifests the following >> bug: >> >> $ dash -c 'x=; echo $((x))' >> dash: 1: Illegal number: >> >> This error is printed instead of the expected default "0" that should be >> substituted for an empty variable in an arithmetic expression. >> >> The bug does not occur on Linux, NetBSD, OpenBSD or Solaris. > > There is no reason why dash should behave differently on FreeBSD vs. > Linux, so I agree with your patch, but isn't this non-standard, isn't > either behaviour allowed? I don't think so. 2.6.4 Arithmetic Expansion: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04 "The arithmetic expression shall be processed according to the rules given in Arithmetic Precision and Operations [...]". Arithmetic Precision and Operations: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_01_02_01 "All variables shall be initialized to zero if they are not otherwise assigned by the input to the application." Also, consensus among existing shells appears to be universal. > This looks good, it does the job, but it can be simplified a bit: > > If errno == EINVAL, then p == s is already known. > > If errno != 0 && p == s, then errno == EINVAL is already known. > > This allows simplifying to either of the following: > > if (errno != 0 && errno != EINVAL) > if (errno != 0 && p != s) Good point. > But perhaps > > if (errno == ERANGE) > > is all that's needed here. Explain? Thanks, - M. -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html