correctcomputation / checkedc-clang

This is the primary development repository for 3C, a tool for automatically converting legacy C code to the Checked C extension of C, which aims to enforce spatial memory safety. This repository is a fork of Checked C's.
14 stars 5 forks source link

Regression in rewriter #204

Closed Machiry closed 4 years ago

Machiry commented 4 years ago

Consider the following code:

#define ulong   unsigned long

ulong *     TOP;
ulong           channelColumns;

void
DescribeChannel(void)
{
    ulong   col;
    TOP = (ulong *)malloc((channelColumns+1) * sizeof(ulong));
    TOP[col] = 0;
}

When you run with alltypes: ./cconv-standalone -alltypes <foo.c>, you get the following:

#define ulong   unsigned long

_Array_ptr<unsigned long> TOP = ((void * TOP)0);
ulong           channelColumns;

void
DescribeChannel(void)
{
    ulong   col;
    TOP = (_Array_ptr<unsigned long> )malloc((channelColumns+1) * sizeof(ulong));
    TOP[col] = 0;
}

See the invalid cast:

_Array_ptr<unsigned long> TOP = ((void * TOP)0);

This has to be:

_Array_ptr<unsigned long> TOP = ((void *)0);

Some issue with the latest DeclRewriter refactoring.

john-h-kastner commented 4 years ago

I think this is much older. See b960a3bcfd53369888888d4fd874045336910341 at the latest, but I think it goes back farther.