ja:rule:num:整数値のオーバーフローを検出_防止する
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ja:rule:num:整数値のオーバーフローを検出_防止する [2016/03/19 00:30] – yohgaki | ja:rule:num:整数値のオーバーフローを検出_防止する [2017/06/30 11:32] (current) – [参考文献] yohgaki | ||
|---|---|---|---|
| Line 40: | Line 40: | ||
| </ | </ | ||
| - | このコードは32bit/ | + | このコードは32bit/ |
| エラー例 | エラー例 | ||
| Line 55: | Line 55: | ||
| ===== 適合コード例 ===== | ===== 適合コード例 ===== | ||
| - | PHPで整数オーバーフローを検出するのは比較的簡単です。PHPは整数オーバーフローを起こす場合は自動的に浮動小数点型に変換されます。64bit環境では符号付き32bit整数の範囲外であるか、のチェックも必要です。 | + | PHPで整数オーバーフローを検出するのは比較的簡単である。PHPは整数オーバーフローを起こす場合は自動的に浮動小数点型に変換される。64bit環境では符号付き32bit整数の範囲外であるか、のチェックも必要である。 |
| <code php> | <code php> | ||
| Line 74: | Line 74: | ||
| // Check signed 32 bit integer overflow | // Check signed 32 bit integer overflow | ||
| // Under 32 bit OS, $myint became float. Under 64 bit OS, check 32 bit integer range | // Under 32 bit OS, $myint became float. Under 64 bit OS, check 32 bit integer range | ||
| - | if (is_float($myint) || $myint < 0xFFFFFFFF | + | if (is_float($myint) || $myint < 0x80000000 |
| throw new Exception(' | throw new Exception(' | ||
| } | } | ||
| Line 103: | Line 103: | ||
| ===== 参考文献 ===== | ===== 参考文献 ===== | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
ja/rule/num/整数値のオーバーフローを検出_防止する.1458347435.txt.gz · Last modified: 2016/03/19 00:30 by yohgaki
