Menu

#132 Pointer difference operations have the wrong type.

Bug
closed-fixed
nobody
5
2012-07-04
2012-06-27
Jim Grundy
No

Pointer difference operations should have some type that corresponds to ptrdiff_t, but the cabs2cil transformation creates them with type "int". The "int" type is often not as big as ptrdiff_t. The result of this that sometimes the types of the arguments of binary operators do not match (though CIL thinks they do).

Consider the following program:

int main()
{
int i;
int *p = &i;
int *q = &p;
short s = 1;
long d = (p - q) + s;

return 0;
}

CIL will translate the statement "d = (p - q) + s;" to "d = (long)((p - q) + (int)s);". It should have created "d = (long)((p - q) + (ptrdiff_t)s);".

A patch to fix the bug is attached.

Discussion

  • Gabriel Kerneis

    Gabriel Kerneis - 2012-07-04
    • status: open --> closed-fixed
     
  • Gabriel Kerneis

    Gabriel Kerneis - 2012-07-04

    Applied, thanks.

     

Log in to post a comment.