本文介绍了转移存储空间的所有权夹板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用在C简单的链表实现,我怎么告诉夹板,我转数据的所有权

Using a simple linked list implementation in C, how do I tell Splint that I am transfer ownership of 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;
}

我收到此错误信息:

I get this error message:

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)

我要告诉夹板固定的释放数据的责任被转移到列表中的数据结构。

I want to tell Splint that responsibility of freeing data is transfered to the list data-structure.

推荐答案

解决方案是在的的。基本上,函数签名改成这样:

The solution is in the Splint manual for function interfaces. Basically, change the function signature to this:

static /*@null@*/ list* new_list(/*@notnull@*/ /*@only@*/ void* data)
    /*@defines result->data @*/

虽然这样做的时候,我们会得到一个新的错误:

Although we'll get a new error when doing this:

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)

这篇关于转移存储空间的所有权夹板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 18:00