Configuration | Rules 4.2.1.2 SA0021 - SA0040 | SA0021 - SA0040 4.2.1.2.1 SA0021: Transporting the address of a temporary variable | SA0021: Transporting the address of a temporary variable Sample: Method FB_Sample.SampleMethod: METHOD SampleMethod : XWORD VAR fVar : LREAL; END_VAR SampleMethod := ADR(fVar); MAIN program: PROGRAM MAIN VAR nReturn : XWORD; fbSample : FB_Sample; END_VAR nReturn := fbSample.SampleMethod(); // => SA0021 4.2.1.2.2 SA0022: (Possibly) unassigned return value | SA0022: (Possibly) unassigned return value Sample: FUNCTION F_Sample : DWORD VAR_INPUT nIn : UINT; END_VAR VAR nTemp :
INT; END_VAR nIn := nIn + UINT#1; IF (nIn > UINT#10) THEN nTemp := 1; // => SA0022 ELSE F_Sample := DWORD#100; END_IF TE1200 30 Version: 2.11.1 Function Determines assignments of addresses of temporary variables (variables on the stack) to non-temporary variables. Reason Local variables of a function or method are created on the stack and exist only while the function or method is processed. If a pointer points to such a variable after processing the method or function, then this pointer can be used to access undefined memory or an incorrect variable in another function. This situation must be avoided in any case.
Importance High Function Determines all functions and methods containing an execution thread without assignment to the return value. Reason An unassigned return value in a function or method indicates missing code. Even if the return value always has a default value, it is useful to explicitly assign it again in any case, in order to avoid ambiguities. Importance Medium