From 14e4e2d40f91cde56f5692beb7a0c8edf374c0a2 Mon Sep 17 00:00:00 2001
From: Marco Gario
+ Arithmetic calculations involving integers should be checked to ensure that overflow or
+ underflow cannot occur, as this may cause incorrect results or program crashes.
+
Before performing an integer operation that may cause an overflow, check the operands to ensure
that the result of the operation will fit into the value range of the type. Alternatively, check
the result of the operation to see whether it overflowed.
- start + offset may overflow if
- either start or offset is very large, which will cause the indexing
- operation to panic at runtime:
- start + offset overflows:
-
+ In the following example snippet, the addition start + offset may overflow if
+ either start or offset is very large, which will cause the indexing
+ operation to panic at runtime:
+
+ One way to prevent this is to check whether start + offset overflows:
+