From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] compiler double bug.
Date: Tue, 1 Dec 2009 13:41:32 -0500 [thread overview]
Message-ID: <dc10137c2661c11595d2aa2ca370ba45@brasstown.quanstro.net> (raw)
In-Reply-To: <<a4d2df97e4d97d460ae33ca0800a4060@terzarima.net>>
On Tue Dec 1 11:58:47 EST 2009, forsyth@terzarima.net wrote:
> i hadn't noticed the changed example.
> it's removing the cast, which probably isn't right, although
> in that particular case it's probably better
> that it should trap (because the result is wrong).
> what is the actual code in awk that's equivalent to that sequence?
>
all these fault:
minooka; awk 'BEGIN {
s = "01234567890";
printf "%x\n", 4215866817.
g = 1. # delayed fpe
printf "%08x", 4215866817.
print substr(s, 4215866817., 1)
s = substr(s, 1, 4215866817.)
g= 1. # delayed fpe
printf utf(4215866817.);
g= 1. # delayed fpe
}'
a (not-so-elegant) fix follows.
- erik
proto.h:92,98 - /n/dump/2009/1129/sys/src/cmd/awk/proto.h:92,97
extern void funnyvar(Cell *, const char *);
extern char *setsval(Cell *, const char *);
extern double getfval(Cell *);
- extern unsigned long getival(Cell *, unsigned long, unsigned long);
extern char *getsval(Cell *);
extern char *getpssval(Cell *); /* for print */
extern char *tostring(const char *);
diff: can't stat /n/dump/2009/1129/sys/src/cmd/awk/trans.c
run.c:50,57 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:50,55
}
*/
- #define Imax ULONG_MAX
-
/* do we really need these? */
/* #ifdef _NFILE */
/* #ifndef FOPEN_MAX */
run.c:355,361 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:353,359
case EXIT:
if (a[0] != NULL) {
y = execute(a[0]);
- errorflag = getfval(y) != 0.;
+ errorflag = (int) getfval(y);
tempfree(y);
}
longjmp(env, 1);
run.c:752,765 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:750,770
setsval(x, "");
return(x);
}
- m = getival(y, 1, k); /* 1 <= m <= k */
+ m = (int) getfval(y);
+ if (m <= 0)
+ m = 1;
+ else if (m > k)
+ m = k;
tempfree(y);
if (a[2] != 0) {
- n = getival(z, 0, k-m);
- /* n <= 0 <= k-m */
+ n = (int) getfval(z);
tempfree(z);
} else
n = k - 1;
+ if (n < 0)
+ n = 0;
+ else if (n > k - m)
+ n = k - m;
dprintf( ("substr: m=%d, n=%d, s=%s\n", m, n, s) );
y = gettemp();
temp = s[n+m-1]; /* with thanks to John Linderman */
run.c:804,810 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:809,815
char *p, *t;
const char *os;
Cell *x;
- int flag = 0, n, ch;
+ int flag = 0, n;
int fmtwd; /* format width */
int fmtsz = recsize;
char *buf = *pbuf;
run.c:838,844 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:843,849
if (*s == '*') {
x = execute(a);
a = a->nnext;
- sprintf(t-1, "%d", fmtwd=getival(x, Imax, Imax));
+ sprintf(t-1, "%d", fmtwd=(int) getfval(x));
if (fmtwd < 0)
fmtwd = -fmtwd;
adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format");
run.c:894,901 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:900,907
sprintf(p, "%s", t);
break;
case 'f': sprintf(p, fmt, getfval(x)); break;
- case 'd': sprintf(p, fmt, getival(x, Imax, Imax)); break;
- case 'u': sprintf(p, fmt, getival(x, Imax, Imax)); break;
+ case 'd': sprintf(p, fmt, (long) getfval(x)); break;
+ case 'u': sprintf(p, fmt, (int) getfval(x)); break;
case 's':
t = getsval(x);
n = strlen(t);
run.c:907,915 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:913,920
break;
case 'c':
if (isnum(x)) {
- ch = getival(x, Imax, Imax);
- if (ch)
- sprintf(p, fmt, ch);
+ if (getfval(x))
+ sprintf(p, fmt, (int) getfval(x));
else {
*p++ = '\0'; /* explicit null byte */
*p = '\0'; /* next output will start here */
Awkfloat
strtonum(Cell *x)
{
run.c:1566,1579 - /n/dump/2009/1129/sys/src/cmd/awk/run.c:1583,1589
u = fflush(fp);
break;
case FUTF:
- r = getival(x, Imax, Imax);
- if(r < 0)
- r = -r;
- if(r > Runemax){
- WARNING("utf argument out-of-range %g", getfval(x));
- r = Runeerror;
- }
- wc = r;
+ wc = (int)getfval(x);
mbc[wctomb(mbc, wc)] = 0;
tempfree(x);
x = gettemp();
next parent reply other threads:[~2009-12-01 18:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <<a4d2df97e4d97d460ae33ca0800a4060@terzarima.net>
2009-12-01 18:41 ` erik quanstrom [this message]
2009-12-01 21:35 ` Charles Forsyth
2009-12-01 22:19 ` Charles Forsyth
[not found] <<d5e75e65219a1207aad92a000119dba0@terzarima.net>
2009-12-02 1:59 ` erik quanstrom
[not found] <<d893fc0b1d0b52a1dd610d7eb14279d3@terzarima.net>
2009-12-01 22:31 ` erik quanstrom
2009-12-01 23:33 ` Charles Forsyth
[not found] <<0232aa110f8423b8381e009b6cda7cef@terzarima.net>
2009-12-01 21:45 ` erik quanstrom
[not found] <<dc10137c2661c11595d2aa2ca370ba45@brasstown.quanstro.net>
2009-12-01 18:53 ` erik quanstrom
[not found] <<615bb2c21f211025b5d9aba799fffe0d@terzarima.net>
2009-12-01 16:39 ` erik quanstrom
2009-12-01 17:02 ` Charles Forsyth
2009-12-01 16:39 ` erik quanstrom
[not found] <<9987774388a28369b01fa5658da35af9@terzarima.net>
2009-12-01 15:05 ` erik quanstrom
2009-12-01 16:31 ` Charles Forsyth
[not found] <<2d42b6b28807634253ba28dc55a96de6@brasstown.quanstro.net>
2009-12-01 8:02 ` erik quanstrom
2009-12-01 9:43 ` Charles Forsyth
2009-12-01 9:45 ` Charles Forsyth
2009-12-01 7:55 erik quanstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc10137c2661c11595d2aa2ca370ba45@brasstown.quanstro.net \
--to=quanstro@quanstro.net \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).