Commit 53c32a2
committed
rpng: gate pass_size 4 GiB cap on 64-bit size_t
GCC 4.0 on 32-bit PPC (and any ILP32 build) reports:
rpng.c:1597: warning: comparison is always false due to
limited range of data type
The pass_size cap checks (uint64_t)pass_size >= 0x100000000ULL.
On ILP32 size_t is 32-bit (max 0xFFFFFFFF = 2^32 - 1), one less
than the 2^32 threshold. Widening to uint64_t doesn't extend the
value range, so the comparison is statically unreachable and GCC
emits a dead-code warning.
The cap itself isn't wrong - on 64-bit, pass_size can genuinely
exceed 4 GiB (e.g. 30000x30000 16bpc-RGBA intermediate inflate
buffer needs 7 GiB) and we want to reject before malloc. On 32-bit
pass_size literally cannot reach 4 GiB because size_t can't
represent it, so the check is redundant by construction.
Preprocessor-gate the pass_size clause on SIZE_MAX > 0xFFFFFFFFULL:
if ((uint64_t)width * height * sizeof(uint32_t) >= 0x100000000ULL
#if SIZE_MAX > 0xFFFFFFFFULL
|| (uint64_t)pass_size >= 0x100000000ULL
#endif
)
return false;
The output-size clause stays unguarded - width * height * 4 can
overflow 32-bit even when each operand is 32-bit wide (100000 *
100000 * 4 is ~40 GiB), so that cap is meaningful on 32-bit too.
SIZE_MAX is already in scope via the existing <stdint.h> include.
No behavior change on 64-bit; 32-bit loses the warning.1 parent 6a9ff6a commit 53c32a2
1 file changed
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1587 | 1587 | | |
1588 | 1588 | | |
1589 | 1589 | | |
1590 | | - | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
1591 | 1598 | | |
1592 | 1599 | | |
1593 | 1600 | | |
1594 | 1601 | | |
1595 | 1602 | | |
1596 | 1603 | | |
1597 | | - | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
1598 | 1608 | | |
1599 | 1609 | | |
1600 | 1610 | | |
| |||
0 commit comments