beckhoff TE1200 — 4.2.1.2.18 SA0039: Possible null pointer dereferences

Configuration | Rules IF bIn THEN nIn := 500; // => SA0037 bOut := TRUE; END_IF 4.2.1.2.17 SA0038: Read access to output variable | SA0038: Read access to output variable Sample: Function block FB_Sample: FUNCTION_BLOCK FB_Sample VAR_OUTPUT bOut : BOOL; nOut : INT; END_VAR VAR bLocal : BOOL; nLocal : INT; END_VAR Method FB_Sample.SampleMethod: IF bOut THEN // => SA0038 bLocal := (nOut > 100); // => SA0038 nLocal := nOut; // => SA0038 nLocal := 2*nOut; // => SA0038 END_IF 4.2.1.2.18 SA0039: Possible null pointer dereferences | SA0039: Possible null pointer dereferences Sample 1: PROGRAM MAIN VAR pInt1 : POINTER TO INT; pInt2 : POINTER TO INT; pInt3 : POINTER TO INT; nVar1 : INT; nCounter :

INT; END_VAR nCounter := nCounter + INT#1; pInt1 := ADR(nVar1); pInt1^ := nCounter; // no error pInt2^ := nCounter; // => SA0039 nVar1 := pInt3^; // => SA0039 Sample 2: 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 37 Version: 2.11.1 Function Determines output variables (VAR OUTPUT) that are subject to read access within the _ POU. Reason The IEC-61131-3 standard prohibits reading an output within a function block.

It indicates that the output is not only used as an output but also as a temporary variable for intermediate results. Such dual use should be avoided. Importance Low Function Determines code positions at which a NULL-pointer may be dereferenced. Reason A pointer should be checked before each dereferencing to see if it is not equal to 0. Otherwise, access violations may occur at runtime. Importance High