Date: Sun, 6 Apr 2003 06:24:50 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Alex Semenyaka <alexs@ratmir.ru> Cc: freebsd-hackers@freebsd.org Subject: Re: /bin/sh and BIG NUMBERS Message-ID: <20030406032450.GC4130@gothmog.gr> In-Reply-To: <20030405030629.GA2669@snark.ratmir.ru> References: <20030405030629.GA2669@snark.ratmir.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2003-04-05 07:06, Alex Semenyaka <alexs@ratmir.ru> wrote: > I found that /bin/sh cannot handle numbers those do not fit to integer > type. That is not too bad. Too bad that it just silently warps them > in arithmetical operations: > > alexs@snark> /bin/sh -c 'echo $((10000000000-1))' > 2147483646 > > That was not a problem 5 years ago... But now we have a lot of 64-bits > values. So those old scripts which perfectly worked for a long time > now can give wrong results, and you will not be able even to notice > it, there is no any diagnostics or such. The simplest way to fix it is > to switch internal /bin/sh arithmetics from 32 to 64-bits (you know, > approach "640K ought to be enough for anybody"). I've did the patch > for this (below), please, look at it. Any comments or suggestions? > > diff -u -U1 -r ../sh.old/arith.h ./arith.h > --- ../sh.old/arith.h Fri Jul 19 08:38:51 2002 > +++ ./arith.h Sat Apr 5 06:26:48 2003 > @@ -36,3 +36,3 @@ > > -int arith(char *); > +long long arith(char *); > int expcmd(int , char **); > > [snip rest of long-long using patch] Nice idea, but we should probably ask the -standards people if we can/should make this use uint64_t and %jd instead of `long long' (using %qd is deprecated and %lld is advised in printf(3) anyway). : giorgos@gothmog[06:19]/tmp/lala$ cat lala.c : #include <limits.h> : #include <stdint.h> : #include <stdio.h> : : int : main(void) : { : uint64_t foo; : : foo = UINT_MAX; : printf("%jd\n", foo); : return (0); : } : giorgos@gothmog[06:19]/tmp/lala$ make WARNS=5 : Warning: Object directory not changed from original /tmp/lala : cc -O -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k \ : -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \ : -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow \ : -Wcast-align -Wuninitialized -Wformat=2 -Wno-format-extra-args \ : -Werror -c lala.c : cc -O -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k \ : -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \ : -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow \ : -Wcast-align -Wuninitialized -Wformat=2 -Wno-format-extra-args \ : -Werror -o lala lala.o : giorgos@gothmog[06:19]/tmp/lala$ ./lala : 4294967295 : giorgos@gothmog[06:19]/tmp/lala$
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030406032450.GC4130>