SA0046: Possible use of not initialised interface
Detects the use of interfaces that were not initialized before being used
Justification: An interface reference should be checked for <> 0 before it is used. Otherwise an access violation may occur during access.
Importance: High
Example 115. Example
//Declaration of INTERFACE ITF and assigned METH2: METHOD METH2 : BOOL VAR_INPUT iInput2:INT; END_VAR
//Declaration of INTERFACE Master_ITF1 and assigned METH: METHOD METH : BOOL VAR_INPUT iInput:INT; END_VAR
PROGRAM PLC_PRG VAR instPOU : POU; instITF : ITF; instMasterITF1 : Master_ITF1; instMasterITF2 : Master_ITF2; iDummy : INT; xDummy : BOOL; instNoInitITF : ITF; instNoInitITF2 : ITF; instNoInitMasterITF1 : Master_ITF1; instNoInitMasterITF2 : Master_ITF2; END_VAR
instITF := instPOU; xDummy := instITF.METH(iInput := iDummy); // OK instMasterITF1 := instPOU; xDummy := instMasterITF1.METH(iInput := iDummy); // OK xDummy := instNoInitITF.METH(iInput := INT#1); // SA0046 xDummy := instNoInitITF.METH2(iInput2 := INT#2); // SA0046 xDummy := instNoInitMasterITF1.METH(iInput := INT#3); // SA0046 iDummy := instNoInitMasterITF2.Prop; // SA0046 IF instNoInitITF <> 0 THEN instNoInitITF.Prop; // OK, because the interface can't be 0 END_IF
Output in the Messages view:
SA0046: Possible use of not initialised interface 'instNoInitITF'
SA0046: Possible use of not initialised interface 'instNoInitITF'
SA0046: Possible use of not initialised interface 'instNoInitMasterITF1'
SA0046: Possible use of not initialised interface 'instNoInitMasterITF2'