1


I'm working on a game at the moment, and I'm having an issue with splint on the following code to add new enemy structs to my linked list.

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 gives the warning:

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)

Line 57 is the last return in the function.

Now, I'm fairly confident my code cannot return undefined values, as I either set all fields, or don't change anything and drop out.

Is there some case I'm missing out where I send back stuff undefined? If not, what's the best way to stop splint giving this warning?

Minifig666
  • 111
  • 1
  • 5

0 Answers0