Skip to main content

SA0175: Suspicious operation on string

Note

Do not always enable this rule. Enable the rule only when necessary to find the locations in the code which should be checked when converting to UTF-8 encoding.

Checks if the project option UTF-8 Encoding for STRING can be enabled. This is the case when no code locations with suspicious operations are found.

When switching to UTF-8 encoding, the first 127 characters correspond to ASCII encoding. However, all other characters are encoded with more than one byte. This can cause a change in behavior when processing strings. As a result, a string literal containing non-ASCII characters may become longer. Or access in a string by index can access the wrong element. Finally, even access to an invalid byte offset can occur.

When the rule is active, all code locations containing any of the following constructs are reported:

  • Index access to a byte string

    Example: str[2]

    Message: SA0175: Enumeration with attribute 'strict': Suspicious operation on string: index access '<expression>'

  • Address access to single-byte strings

    Example: ADR(str)

    Message: sa_icon_message.png SA0175:Enumeration with attribute 'strict': Suspicious operation on string: Possible index access '<expression>'

  • Call of string functions of the Standard library, except when calling the CONCAT and LEN functions

    Message: sa_icon_message.png SA0175:Enumeration with attribute 'strict': Suspicious operation on string: Possible index access '<expression>'

  • Byte literal containing non-ASCII characters

    Examples:

    str := '99€';
    str :='Ä';

    Message: sa_icon_message.png SA0175: Suspicious operation on string: Literal '<literal>' contains non-ASCII characters