mirror of
https://github.com/github/codeql.git
synced 2026-07-05 19:45:29 +02:00
Refactoring queries WIP
This commit is contained in:
20
cpp/ql/src/experimental/refactoring/cstrings.ql
Normal file
20
cpp/ql/src/experimental/refactoring/cstrings.ql
Normal file
@@ -0,0 +1,20 @@
|
||||
import cpp
|
||||
|
||||
class StringVariable extends Variable {
|
||||
StringVariable() {
|
||||
this.getType().(PointerType).stripType().getName() = "char"
|
||||
}
|
||||
}
|
||||
|
||||
class StringField extends StringVariable, Field
|
||||
{
|
||||
}
|
||||
|
||||
class StringParameter extends StringVariable, Parameter
|
||||
{
|
||||
}
|
||||
|
||||
from StringVariable f
|
||||
where f.getFile().getRelativePath().matches("c/extractor/src/%")
|
||||
and not f.getASpecifier().getName() = "extern"
|
||||
select f, f.getFile().getRelativePath()
|
||||
@@ -0,0 +1,9 @@
|
||||
import cpp
|
||||
import relevant
|
||||
|
||||
from Function fn
|
||||
where
|
||||
fn.getNamespace() instanceof GlobalNamespace and
|
||||
not exists(fn.getDeclaringType()) and
|
||||
is_relevant_result(fn.getFile())
|
||||
select fn, "This function is not declared in a namespace", fn.getFile().getRelativePath()
|
||||
@@ -0,0 +1,4 @@
|
||||
import cpp
|
||||
|
||||
from Function fn
|
||||
where not exists(fn.getDeclaringType()) and is_relevant_result(fn.getFile())
|
||||
25
cpp/ql/src/experimental/refactoring/global_variables.ql
Normal file
25
cpp/ql/src/experimental/refactoring/global_variables.ql
Normal file
@@ -0,0 +1,25 @@
|
||||
// Flags use of global variables
|
||||
import cpp
|
||||
|
||||
class RelevantGlobalVariable extends GlobalVariable
|
||||
{
|
||||
RelevantGlobalVariable() {
|
||||
any()
|
||||
}
|
||||
}
|
||||
|
||||
predicate is_valid_global_variable(Variable var) {
|
||||
var.getType().stripType().getName() = "trie_node" or
|
||||
var.getType().isConst() or
|
||||
var.getType().isDeeplyConst() or
|
||||
var.isConstexpr() or
|
||||
var.getType() instanceof ArrayType or
|
||||
var.getASpecifier().getName() = "extern" or
|
||||
var.getFile().getRelativePath().matches("c/extractor/edg/%")
|
||||
}
|
||||
|
||||
from GlobalVariable globalVariable, string typeName
|
||||
where
|
||||
not is_valid_global_variable(globalVariable) and
|
||||
typeName = globalVariable.getType().stripType().getName()
|
||||
select globalVariable, typeName, globalVariable.getFile().getRelativePath()
|
||||
7
cpp/ql/src/experimental/refactoring/printf.ql
Normal file
7
cpp/ql/src/experimental/refactoring/printf.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
import cpp
|
||||
import relevant
|
||||
|
||||
from Call call
|
||||
where call.getTarget().getName().matches("%printf")
|
||||
and is_relevant_result(call.getFile())
|
||||
select call, "Call to a printf formatter", call.getFile().getRelativePath()
|
||||
6
cpp/ql/src/experimental/refactoring/relevant.qll
Normal file
6
cpp/ql/src/experimental/refactoring/relevant.qll
Normal file
@@ -0,0 +1,6 @@
|
||||
import cpp
|
||||
|
||||
predicate is_relevant_result(File file)
|
||||
{
|
||||
not file.getRelativePath().matches("c/extractor/edg%")
|
||||
}
|
||||
25
cpp/ql/src/experimental/refactoring/write_to_stream.ql
Normal file
25
cpp/ql/src/experimental/refactoring/write_to_stream.ql
Normal file
@@ -0,0 +1,25 @@
|
||||
import cpp
|
||||
|
||||
class ACompressedFileWrite extends Function {
|
||||
ACompressedFileWrite() {
|
||||
this.getName() = "operator<<" and
|
||||
this.getParameter(0).getType().stripType().getName() = "a_compressed_file"
|
||||
}
|
||||
}
|
||||
|
||||
class LabelDefinition extends Call {
|
||||
LabelDefinition() {
|
||||
this.getTarget() instanceof ACompressedFileWrite and
|
||||
this.getArgument(1).(StringLiteral).getValue().matches("=%")
|
||||
}
|
||||
}
|
||||
|
||||
predicate is_valid_file_write(Call call) {
|
||||
call.getFile().getBaseName() = "dbscheme.cpp"
|
||||
}
|
||||
|
||||
from Call call
|
||||
where
|
||||
call.getTarget() instanceof ACompressedFileWrite
|
||||
and not is_valid_file_write(call)
|
||||
select call
|
||||
Reference in New Issue
Block a user