다음을 통해 공유


PREfast Warning 268 (Windows CE 5.0)

Send Feedback

268 - Incorrect order of operations.
Additional Information: (<type1>) (<type2>) x+y.
Recommended Fix: Probable misparenthesization of (<type1>) ((<type2>) x+y).

This warning indicates that a complex cast expression that may involve a precedence problem when performing pointer arithmetic. Because casts group more closely than binary operators, the result might not be what the programmer intended.

In some cases, this defect can result in incorrect behavior or a program crash.

In an expression such as:

(char *)p + offset

the offset is interpreted as an offset in characters; however, an expression such as:

(int *)(char *)p + offset

is equivalent to:

((int *)(char *)p) + offset

and so the offset is interpreted as an offset in integers. In other words, it is equivalent to:

(int *)((char *)p + offset * sizeof(int))

which is not likely to be what is intended.

Depending on the relative sizes of the two types, this can lead to a buffer overrun.

Example

Defective Source

int *ptr = (int *)(char *)p + offset_in_bytes;

Corrected Source

int *ptr = (int *)((char *)p + offset_in_bytes);

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.