使用C中的简单链表实现,如何告诉Splint我正在转让所有权data
?
typedef struct {
void* data;
/*@null@*/ void* next;
} list;
static /*@null@*/ list* new_list(/*@notnull@*/ void* data)
{
list* l;
l = malloc(sizeof(list));
if (l == NULL)
return NULL;
l->next = NULL;
l->data = data;
return l;
}
我收到此错误消息:
Implicitly temp storage data assigned to implicitly
only: list->data = data
Temp storage (associated with a formal parameter) is transferred to a
non-temporary reference. The storage may be released or new aliases created.
(Use -temptrans to inhibit warning)
我想告诉Splint,释放的责任data
已转移到列表数据结构。
解决方案在功能接口的Splint手册中。基本上,将函数签名更改为:
static /*@null@*/ list* new_list(/*@notnull@*/ /*@only@*/ void* data)
/*@defines result->data @*/
尽管这样做时会收到一个新错误:
int main()
{
list* l = new_list("hej");
return 0;
}
Observer storage passed as only param:
new_list ("hej")
Observer storage is transferred to a non-observer reference. (Use
-observertrans to inhibit warning)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句