SA0046: Possible use of not initialized interfaces
Function | Determines the use of interfaces that may not have been initialized before the use. |
Reason | An interface reference should be checked for <> 0 before it is used, otherwise an access violation may occur at runtime. |
Importance | High |
Samples:
Interface I_Sample:
INTERFACE I_SampleMETHOD SampleMethod : BOOL
VAR_INPUT
nInput : INT;
END_VARFunction block FB_Sample:
FUNCTION_BLOCK FB_Sample IMPLEMENTS I_SampleMETHOD SampleMethod : BOOL
VAR_INPUT
nInput : INT;
END_VARMAIN program:
PROGRAM MAIN
VAR
fbSample : FB_Sample;
iSample : I_Sample;
iSampleNotSet : I_Sample;
nParam : INT;
bReturn : BOOL;
END_VARiSample := fbSample;
bReturn := iSample.SampleMethod(nInput := nParam); // no error
bReturn := iSampleNotSet.SampleMethod(nInput := nParam); // => SA0046Overview of the rules on "dereferencing"
Pointer | |
|---|---|
Dereferencing of pointers in the declaration part | |
Possible null pointer dereferences in the implementation part | |
References | |
|---|---|
Use of references in the declaration part | |
Possible use of not initialized reference in the implementation part | |
Interfaces | |
|---|---|
Possible use of not initialized interface in the implementation part | |