mudflap: Q re __mf_check READ/WRITE

Eyal Lebedinsky eyal@eyal.emu.id.au
Sun Apr 27 01:38:00 GMT 2003


Looking, for example, at the fread() wrapper. I now have it like:

WRAPPER2(size_t, fread, void *ptr, size_t size, size_t nmemb, FILE
*stream)
{
  MF_VALIDATE_EXTENT (stream, sizeof (*stream), __MF_CHECK_WRITE,
    "fread stream");
  MF_VALIDATE_EXTENT (ptr, size * nmemb, __MF_CHECK_WRITE, "fread
buffer");
  return fread (ptr, size, nmemb, stream);
}

I check 'stream' as __MF_CHECK_WRITE to indicate that this function
will write to it. But I also want to say that it will read from it,
and if it was never written to then I do want a violation to be
recorded.

So, as I see that the two access types cannot be combined (values
are 0 and 1), should I call __mf_check() twice, first READ then WRITE?


Now a bit off topic. If I know that an object is of a known type,
I think that I should be able to tag it and then later check that
it is the correct one. For example, the fopen() will mark the
resulting object as "file handle" and check for it in the fread().
The object pool allows me to effectively extend a pointer with as
many attributes as I want. Naturally, the compiler can add these
tags as it knows the type of the object (FILE *). This way one
can even catch the sneaky misuse of 'void *' where data in moved
in and out of with different types. Does this make sense? I know
that C is not strong enough here ('FILE *' may mean something
different in two compilation units).

--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>



More information about the Gcc mailing list