beckhoff TE1200 — 4.2.1.6.5 SA0125: References in initializations

Configuration | Rules 4.2.1.6.4 SA0124: Dereference access in initializations | SA0124: Dereference access in initializations Samples: FUNCTION_BLOCK FB_Test VAR_INPUT pStruct : POINTER TO ST_Test; refStruct : REFERENCE TO ST_Test; END_VAR VAR bPointer : BOOL := pStruct^.bTest; // => SA0124: Dereference access in initialization bRef : BOOL := refStruct.bTest; // => SA0125: Reference used in initialization END_VAR bPointer := pStruct^.bTest; // => SA0039: Possible null pointer dereference 'pStruct^' bRef := refStruct.bTest; // => SA0145:

Possible use of not initialized reference 'refStruct' IF pStruct 0 THEN bPointer := pStruct^.bTest; // no error SA0039 as the pointer is checked for unequal 0 END_IF IF __ISVALIDREF(refStruct) THEN bRef := refStruct.bTest; // no error SA0145 as the reference is checked via __ISVALIDREF END_IF Overview of the rules on "dereferencing" 4.2.1.6.5 SA0125: References in initializations | SA0125: References in initializations Samples: FUNCTION_BLOCK FB_Test VAR_INPUT pStruct : POINTER TO ST_Test; refStruct : REFERENCE TO ST_Test; END_VAR VAR bPointer : BOOL := pStruct^.bTest; // => SA0124: Dereference access in initialization bRef : BOOL := refStruct.bTest; // => SA0125:

Reference used in initialization END_VAR TE1200 66 Version: 2.11.1 Function Determines all code positions where dereferenced pointers are used in the declaration part of POUs. Reason Pointers and references should not be used for initialization because this can lead to access violations at runtime if the pointer has not been initialized. Importance Medium Pointer Dereferencing of pointers in the declaration part SA0124: Dereference access in initializations [} 66] Possible null pointer dereferences in the implementation part SA0039: Possible null pointer dereferences [} 37] References Use of references in the declaration part SA0125:

References in initializations [} 66] Possible use of not initialized reference in the implementation part SA0145: Possible use of not initialized references [} 69] Interfaces Possible use of not initialized interface in the implementation part SA0046: Possible use of not initialized interfaces [} 41] Function Determines all reference variables used for initialization in the declaration part of POUs. Reason Pointers and references should not be used for initialization because this can lead to access violations at runtime if the pointer has not been initialized. Importance Medium