mirror of
https://github.com/github/codeql.git
synced 2026-01-03 09:40:17 +01:00
Will need subsequent PRs fixing up test failures (due to deprecated methods moving around), but other than that everything should be straight-forward.
31 lines
747 B
Plaintext
31 lines
747 B
Plaintext
/**
|
|
* @name Confusing octal literal
|
|
* @description Octal literal with a leading 0 is easily misread as a decimal value
|
|
* @kind problem
|
|
* @tags readability
|
|
* @problem.severity recommendation
|
|
* @sub-severity low
|
|
* @precision high
|
|
* @id py/old-style-octal-literal
|
|
*/
|
|
|
|
import python
|
|
|
|
predicate is_old_octal(IntegerLiteral i) {
|
|
exists(string text | text = i.getText() |
|
|
text.charAt(0) = "0" and
|
|
not text = "00" and
|
|
exists(text.charAt(1).toInt()) and
|
|
/* Do not flag file permission masks */
|
|
exists(int len | len = text.length() |
|
|
len != 4 and
|
|
len != 5 and
|
|
len != 7
|
|
)
|
|
)
|
|
}
|
|
|
|
from IntegerLiteral i
|
|
where is_old_octal(i)
|
|
select i, "Confusing octal literal, use 0o" + i.getText().suffix(1) + " instead."
|