Splint警告未定义的存储。请进行理智检查?

时间:2015-10-21 09:37:46

标签: c splint


我正在开发一款游戏,我在下面的代码中遇到了一个问题,将新的敌人结构添加到我的链接列表中。

void generate_enemy(enemy_struct* enemy)
{
    enemy_struct* new_enemy;

    // Make sure the incoming enemy isn't null.
    if(enemy == NULL)
    {
        return;
    }

    // Run through till we find the last enemy in the list.
    while(NULL != enemy->next_enemy)
    {
        enemy = enemy->next_enemy;
    }

    // Create a new enemy and point the last enemy to it.
    new_enemy = malloc(sizeof(enemy_struct));

    // If we're out of memory, don't bother making the new enemy.
    if(NULL == new_enemy)
    {
        return;
    }
    else
    {
        // Initialise the new enemy.
        new_enemy->location = 1;
        new_enemy->motion = ENEMY_STATIC;
        new_enemy->dead = false;//true;
        // Ensure it carries the last enemy flag.
        new_enemy->next_enemy = NULL;

        // Put new enemy in previous enemy.
        enemy->next_enemy = new_enemy;
    }
    return;
}

Splint发出警告:

enemy.c: (in function generate_enemy)
enemy.c:57:12: Storage *(enemy->next_enemy) reachable from parameter contains 4
                  undefined fields: location, motion, dead, next_enemy
  Storage derivable from a parameter, return value or global is not defined.
  Use /*@out@*/ to denote passed or returned storage which need not be defined.
  (Use -compdef to inhibit warning)

第57行是函数中的最后一个返回。

现在,我相当自信我的代码无法返回未定义的值,因为我要么设置所有字段,要么不更改任何内容并退出。

是否有一些情况我错过了我发送回未定义的东西?如果没有,阻止夹板发出此警告的最佳方法是什么?

0 个答案:

没有答案