Skip to content

Strange type mismatch in malloc #29

@jameshfisher

Description

@jameshfisher

Take the following program:

#include <stdlib.h> /* malloc */

void foo()
//@ requires true;
//@ ensures true;
{
  unsigned int count = 3;
  malloc(sizeof(unsigned char) * count);
}

After applying my patch in #28 and running VeriFast, i get the error:

foo.c(8,34-39): Type mismatch. Actual: uintptr_t. Expected: int.

The IDE highlights count as the source of the type error. I don't know where the int expectation is coming from.

I don't understand why, if I pull out the expression into its own variable, VeriFast passes:

#include <stdlib.h> /* malloc */
#include <stddef.h> /* size_t */

void foo()
//@ requires true;
//@ ensures true;
{
  unsigned int count = 3;
  size_t size = sizeof(unsigned char) * count;
  malloc(size);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions