Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 5. Integers (INT) > INT32-C. Ensure that operations on signed integers ...

INT32-C. Ensure that operations on signed integers do not result in overflow

Integer overflow is undefined behavior. This means that implementations have a great deal of latitude in how they deal with signed integer overflow. An implementation that defines signed integer types as being modulo, for example, need not detect integer over-flow. Implementations may also trap on signed arithmetic overflows or simply assume that overflows will never happen and generate object code accordingly (see MSC15-C, “Do not depend on undefined behavior”). For these reasons, it is important to ensure that operations on signed integers do not result in signed overflow. Of particular importance, however, are operations on signed integer values that originate from untrusted sources and are used in any of the following ways:

  • as an array index

  • in any pointer arithmetic

  • as a length or size of an object

  • as the bound of an array (for example, a loop counter)

  • as an argument to a memory allocation function

  • in security-critical code


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial