-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathInvalidAssignmentToErrno.ql
More file actions
35 lines (33 loc) · 1.28 KB
/
InvalidAssignmentToErrno.ql
File metadata and controls
35 lines (33 loc) · 1.28 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
/**
* @id cpp/misra/invalid-assignment-to-errno
* @name RULE-22-4-1: The literal value zero shall be the only value assigned to errno
* @description C++ provides better options for error handling than the use of errno. Errno should
* not be used for reporting errors within project code.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-22-4-1
* scope/single-translation-unit
* maintainability
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import codingstandards.cpp.standardlibrary.Errno
import codingstandards.cpp.Literals
from Assignment assign, VariableAccess errno, Expr rvalue, string message
where
not isExcluded(assign, Preconditions4Package::invalidAssignmentToErrnoQuery()) and
assign.getLValue() = errno and
isErrno(errno) and
assign.getRValue().getExplicitlyConverted() = rvalue and
(
not rvalue instanceof LiteralZero and
message = "Assignment to 'errno' with non-zero literal value '" + rvalue.toString() + "'."
or
assign instanceof AssignOperation and
message =
"Compound assignment to 'errno' with operator '" + assign.getOperator() + "' is not allowed."
)
select assign, message