当我尝试在实例化中分配结构体的字段时,我不断收到错误:
@@
expression e; identifier i;
@@
static struct genl_family i = {
...
- .id = e
...
}
输出:
init_defs_builtins: /usr/lib/coccinelle/standard.h
75 76
Fatal error: exception Failure("minus: parse error: \n = File \"4-15to5-4.cocci\", line 8, column 2, charpos = 75\n around = '.', whole content = - .id = e\n")
我试图分发的代码:
static struct genl_family nl_ecnd_fam = {
.id = GENL_ID_GENERATE,
.name = ECNL_GENL_NAME,
.hdrsize = 0,
.version = 1,
.maxattr = NL_ECNL_ATTR_MAX,
.netnsok = true,
.pre_doit = nl_ecnl_pre_doit,
.post_doit = nl_ecnl_post_doit,
};
有什么建议吗?
这是一个老问题,但这适用于 Coccinelle 版本 1.1.1。以下语义补丁:
@@
expression expr;
identifier i;
@@
static struct genl_family i = {
...,
- .id = expr,
...
};
用于此代码时:
static struct genl_family nl_ecnd_fam = {
.id = GENL_ID_GENERATE,
.name = ECNL_GENL_NAME,
.hdrsize = 0,
.version = 1,
.maxattr = NL_ECNL_ATTR_MAX,
.netnsok = true,
.pre_doit = nl_ecnl_pre_doit,
.post_doit = nl_ecnl_post_doit,
};
给出这个结果:
$ spatch --very-quiet --sp-file field.cocci code/field-example.c
--- code/field-example.c
+++ /tmp/cocci-output-403483-9f1fa0-field-example.c
@@ -1,5 +1,4 @@
static struct genl_family nl_ecnd_fam = {
- .id = GENL_ID_GENERATE,
.name = ECNL_GENL_NAME,
.hdrsize = 0,
.version = 1,