SA0175: Suspicious operation on string

Function

Determines code positions that are suspicious for UTF-8 encoding.

Captured constructs

  1. Index access to a single-byte string
    • Sample: sVar[2]
    • Message: Suspicious operation on string: index access '<expression>'
  2. Address access to a single-byte string
    • Sample: ADR(sVar)
    • Message: Suspicious operation on string: Possible index access '<expression>'
  3. Call of a string function of the Tc2_Standard library except CONCAT and LEN
    • Sample: FIND(sVar, 'a');
    • Message: Suspicious operation on string: Possible index access '<expression>'
  4. Single byte literal containing non-ASCII characters
    • Samples:
      sVar := '99€';
      sVar := 'Ä';
    • Message: Suspicious operation on string: literal '<literal>' contains non-ASCII characters

Importance

Medium

Samples:

VAR
    sVar  : STRING;
    pVar  : POINTER TO STRING;
    nVar  : INT;
END_VAR
// 1) SA0175: Suspicious operation on string: Index access
sVar[2];                         // => SA0175
 
// 2) SA0175: Suspicious operation on string: Possible index access
pVar := ADR(sVar);               // => SA0175
 
// 3) SA0175: Suspicious operation on string: Possible index access
nVar := FIND(sVar, 'a');         // => SA0175
 
// 4) SA0175: Suspicious operation on string: Literal '<...>' contains Non-ASCII character
sVar := '99€';                   // => SA0175
sVar := 'Ä';                     // => SA0175