|
1 | 1 | <!DOCTYPE qhelp SYSTEM "qhelp.dtd"> |
2 | 2 | <qhelp> |
3 | | - <overview> |
4 | | - Arithmetic calculations involving integers should be checked to ensure that overflow or |
5 | | - underflow cannot occur, as this may cause incorrect results or program crashes. |
6 | | - </overview> |
7 | | - <recommendation> |
| 3 | + <overview> |
| 4 | + <p> |
| 5 | + Arithmetic calculations involving integers should be checked to ensure that overflow or |
| 6 | + underflow cannot occur, as this may cause incorrect results or program crashes. |
| 7 | + </p> |
| 8 | + </overview> |
| 9 | + <recommendation> |
| 10 | + <p> |
8 | 11 | Before performing an integer operation that may cause an overflow, check the operands to ensure |
9 | 12 | that the result of the operation will fit into the value range of the type. Alternatively, check |
10 | 13 | the result of the operation to see whether it overflowed. |
11 | | - </recommendation> |
12 | | - <example> |
13 | | - In the following example snippet, the addition <code>start + offset</code> may overflow if |
14 | | - either <code>start</code> or <code>offset</code> is very large, which will cause the indexing |
15 | | - operation to panic at runtime: |
16 | | - <sample src="IntegerOverflow.go" /> |
17 | | - One way to prevent this is to check whether <code>start + offset</code> overflows: |
18 | | - <sample src="IntegerOverflowGood.go" /> |
19 | | - </example> |
20 | | - <references> |
21 | | - <li>Wikipedia <a href="https://en.wikipedia.org/wiki/Integer_overflow">Integer overflow</a>.</li> |
22 | | - </references> |
| 14 | + </p> |
| 15 | + </recommendation> |
| 16 | + <example> |
| 17 | + <p> |
| 18 | + In the following example snippet, the addition <code>start + offset</code> may overflow if |
| 19 | + either <code>start</code> or <code>offset</code> is very large, which will cause the indexing |
| 20 | + operation to panic at runtime: |
| 21 | + </p> |
| 22 | + <sample src="IntegerOverflow.go" /> |
| 23 | + <p> |
| 24 | + One way to prevent this is to check whether <code>start + offset</code> overflows: |
| 25 | + </p> |
| 26 | + <sample src="IntegerOverflowGood.go" /> |
| 27 | + </example> |
| 28 | + <references> |
| 29 | + <li>Wikipedia <a href="https://en.wikipedia.org/wiki/Integer_overflow">Integer overflow</a>.</li> |
| 30 | + </references> |
23 | 31 | </qhelp> |
0 commit comments