-
Hello! I'd like go through all variables in our project which have the I minimized the test case into following lines:
// vi: syntax=ql:
import cpp
from LocalVariable v, string fun
where
v.getAnAttribute().hasName("cleanup") and
fun = v.getAnAttribute().getAnArgument().getValueText()
select v, fun
static inline void foo(char **p) {
if (*p)
*p = free(*p);
}
static inline void erase_char(char *p) {
*p = '\0';
}
int main(void) {
__attribute__((__cleanup__(foo))) char *b_full_attribute;
__attribute__((__cleanup__(erase_char))) char g_not_a_pointer;
puts(b_full_attribute);
printf("%c\n", g_not_a_pointer);
return 0;
} This correctly extracts the cleanup functions, but just as simple strings, since the
Am I overlooking something pretty obvious or it's not possible in the current state? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
sigh, of course it was something obvious, I just had to step back from the computer for a bit: // vi: syntax=ql:
import cpp
predicate functionHasAccess(string fun) {
exists(Function f | f.getName() = fun and f.getAnAttribute().hasName("access") | f.getAnAttribute().getAnArgument().getValueText() = "write_only")
}
from LocalVariable v, string fun
where
v.getAnAttribute().hasName("cleanup") and
fun = v.getAnAttribute().getAnArgument().getValueText() and
functionHasAccess(fun)
select v, fun |
Beta Was this translation helpful? Give feedback.
sigh, of course it was something obvious, I just had to step back from the computer for a bit: