public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* mudflap: Q re __mf_check READ/WRITE
@ 2003-04-27  1:38 Eyal Lebedinsky
  0 siblings, 0 replies; only message in thread
From: Eyal Lebedinsky @ 2003-04-27  1:38 UTC (permalink / raw)
  To: list, gcc, Eigler, Frank Ch.

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/>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-04-26 14:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-27  1:38 mudflap: Q re __mf_check READ/WRITE Eyal Lebedinsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).