Commit 0646323
committed
Ensure match prevents integer overflow
Integers can either be Fixnum or Bignum internally (and the exact
integer at which the types change varies by platform) so support both by
using `RB_INTEGER_TYPE_P` to test values and `NUM2INT` to convert them
to C `int` (which also handles raising `RangeError` for invalid values)
instead of always assuming Fixnum integers.
Dynamically calculate the C's `INT_MAX` using Ruby's
`RbConfig::SIZEOF` hash of C type byte sizes, see
https://docs.ruby-lang.org/en/master/RbConfig.html#SIZEOF rather than
hard-coding the value to 2147483647.1 parent a8a6cbd commit 0646323
2 files changed
+26
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
421 | | - | |
| 420 | + | |
| 421 | + | |
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
| 689 | + | |
690 | 690 | | |
691 | 691 | | |
692 | | - | |
| 692 | + | |
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| |||
1426 | 1426 | | |
1427 | 1427 | | |
1428 | 1428 | | |
1429 | | - | |
| 1429 | + | |
1430 | 1430 | | |
1431 | 1431 | | |
1432 | 1432 | | |
| |||
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
1443 | | - | |
1444 | | - | |
1445 | 1443 | | |
1446 | 1444 | | |
1447 | 1445 | | |
| |||
1470 | 1468 | | |
1471 | 1469 | | |
1472 | 1470 | | |
1473 | | - | |
1474 | | - | |
1475 | 1471 | | |
1476 | 1472 | | |
1477 | 1473 | | |
| |||
1487 | 1483 | | |
1488 | 1484 | | |
1489 | 1485 | | |
1490 | | - | |
1491 | | - | |
1492 | 1486 | | |
1493 | 1487 | | |
1494 | 1488 | | |
| |||
1520 | 1514 | | |
1521 | 1515 | | |
1522 | 1516 | | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
1523 | 1521 | | |
1524 | 1522 | | |
1525 | 1523 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| |||
566 | 570 | | |
567 | 571 | | |
568 | 572 | | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
569 | 579 | | |
570 | 580 | | |
571 | 581 | | |
| |||
584 | 594 | | |
585 | 595 | | |
586 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
587 | 604 | | |
588 | 605 | | |
589 | 606 | | |
| |||
0 commit comments