Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

UB

Description

Example Code

46

Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that does not point into, or just beyond, the same array object.

Forming Out-of-Bounds Pointer, Null Pointer Arithmetic

47

Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that points just beyond the array object and is used as the operand of a unary * operator that is evaluated.

Dereferencing Past the End Pointer, Using Past the End Index

49

An array subscript is out of range, even if an object is apparently accessible with the given subscript, for example, in the lvalue expression a[1][7] given the declaration int a[4][5]).

Apparently Accessible Out-of-Range Index

62

An attempt is made to access , or generate a pointer to just past, a flexible array member of a structure when the referenced object provides no elements for that array.

Pointer Past Flexible Array Member

...

In this noncompliant code example, the function find() attempts to iterate over the elements of the flexible array member buf, starting with the second element. However, because function g() does not allocate any storage for the member, the expression first++ in find() attempts to form a pointer just past the end of buf when there are no elements. This attempt is undefined behavior 62. (see See MSC21-C. Use robust loop termination conditions for more information).

...

This noncompliant code example is similar to an Adobe Flash Player vulnerability that was first exploited in 2008. This code allocates a block of memory , and initializes it with some data. The data does not belong at the beginning of the block, which is left uninitialized. Instead, it is placed offset bytes within the block. The function ensures that the data fits within the allocated block. 

...