Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(126)

Side by Side Diff: src/cmd/gc/mparith1.c

Issue 76730046: code review 76730046: cmd/gc: check exponent overflow and underflow in mparith (Closed)
Patch Set: diff -r cfbe0887d23b https://code.google.com/p/go/ Created 11 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/cmd/gc/go.h ('k') | src/cmd/gc/mparith3.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 #include <u.h> 5 #include <u.h>
6 #include <libc.h> 6 #include <libc.h>
7 #include "go.h" 7 #include "go.h"
8 8
9 /// uses arithmetic 9 /// uses arithmetic
10 10
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 409
410 case 0: 410 case 0:
411 break; 411 break;
412 } 412 }
413 break; 413 break;
414 } 414 }
415 415
416 if(eb) { 416 if(eb) {
417 if(dp) 417 if(dp)
418 goto bad; 418 goto bad;
419 » » a->exp += ex; 419 » » mpsetexp(a, a->exp+ex);
420 goto out; 420 goto out;
421 } 421 }
422 422
423 if(dp) 423 if(dp)
424 dp--; 424 dp--;
425 if(mpcmpfltc(a, 0.0) != 0) { 425 if(mpcmpfltc(a, 0.0) != 0) {
426 if(ex >= dp) { 426 if(ex >= dp) {
427 mppow10flt(&b, ex-dp); 427 mppow10flt(&b, ex-dp);
428 mpmulfltflt(a, &b); 428 mpmulfltflt(a, &b);
429 } else { 429 } else {
430 » » » mppow10flt(&b, dp-ex); 430 » » » if((short)(dp-ex) != dp-ex) {
iant 2014/03/18 21:17:40 I don't quite see why this check is necessary. It
atom 2014/03/18 21:28:59 We want 1/VeryLargeNumber to be rounded to zero, s
431 » » » mpdivfltflt(a, &b); 431 » » » » mpmovecflt(a, 0.0);
432 » » » }
433 » » » else {
434 » » » » mppow10flt(&b, dp-ex);
435 » » » » mpdivfltflt(a, &b);
436 » » » }
432 } 437 }
433 } 438 }
434 439
435 out: 440 out:
436 if(f) 441 if(f)
437 mpnegflt(a); 442 mpnegflt(a);
438 return; 443 return;
439 444
440 bad: 445 bad:
441 yyerror("constant too large: %s", as); 446 yyerror("constant too large: %s", as);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 611
607 if(fv.exp >= 0) { 612 if(fv.exp >= 0) {
608 snprint(buf, sizeof(buf), "%#Bp+%d", &fv.val, fv.exp); 613 snprint(buf, sizeof(buf), "%#Bp+%d", &fv.val, fv.exp);
609 goto out; 614 goto out;
610 } 615 }
611 snprint(buf, sizeof(buf), "%#Bp-%d", &fv.val, -fv.exp); 616 snprint(buf, sizeof(buf), "%#Bp-%d", &fv.val, -fv.exp);
612 617
613 out: 618 out:
614 return fmtstrcpy(fp, buf); 619 return fmtstrcpy(fp, buf);
615 } 620 }
OLDNEW
« no previous file with comments | « src/cmd/gc/go.h ('k') | src/cmd/gc/mparith3.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b