forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvalidCharacterInStringLiteral.ql
More file actions
36 lines (33 loc) · 1.4 KB
/
InvalidCharacterInStringLiteral.ql
File metadata and controls
36 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @id cpp/autosar/invalid-character-in-string-literal
* @name A2-3-1: Use of characters outside the C++ Language Standard basic source character set
* @description Only those characters specified in the C++ Language Standard basic source character
* set shall be used in a string literal.
* @kind problem
* @precision very-high
* @problem.severity recommendation
* @tags external/autosar/id/a2-3-1
* maintainability
* external/autosar/allocated-target/architecture
* external/autosar/allocated-target/design
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Literals
bindingset[s]
string getCharOutsideBasicSourceCharSet(string s) {
result = s.regexpFind("[\\u0000-\\uffff]", _, _) and
not result.regexpMatch("[\\p{Alnum}\\p{Space}_{}\\[\\]#()<>%:;.?*+-/^&|~!=,\\\\\"'@]")
}
from StringLiteral s, string ch
where
not isExcluded(s, NamingPackage::invalidCharacterInStringLiteralQuery()) and
ch = getCharOutsideBasicSourceCharSet(s.getValueText()) and
// wide string and utf8 string literals are exempted.
not s instanceof WideStringLiteral and
not s instanceof Utf8StringLiteral
select s,
"String literal uses the character '" + ch + "' that is outside the language basic character set."