incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: Environment for the test of the string functions memory overrun with example
Date Sun, 09 Jul 2006 21:04:00 GMT
Farid Zaripov wrote:
> tests/include/rw_test_overrun.h
> tests/src/rw_test_overrun.cpp
> tests/strings/rwmatch_test.cpp
> 
>   rw_test_overrun.h contains declaration of the class test_string and 
> #defines used for testing for the memory overrun.
>   rw_test_overrun.cpp contains definition of the class test_string and 
> static utility functions.

Cool! I think this could be useful as a general memory allocator
for the test suite, and might even take place of (or at least
replace the implementation of) the replacement operator new (in
new.cpp) that we've been having problems with on some platforms
(AIX and Windows).

To make it possible I think a more generic and C-ish interface
might be preferable. I.e., instead of a class, how about just
a pair of malloc and free-like functions, say

     enum {
         RW_PROT_READ  = 1 << 0,
         RW_PROT_WRITE = 1 << 1,
         RW_PROT_RDWR  = RW_PROT_READ | RW_PROT_WRITE,
         RW_PROT_EXEC  = 1 << 2,
     };
     void* rw_alloc(size_t nbytes, int flags = -1);

and

     void rw_free(void *addr);

with flags specifying the kind of memory to use (-1 for ordinary,
otherwise protected/guarded) and the protection (read, write, and
execute).

This way we could use the interface to allocate any type of storage,
not just char*. We could also use it as the general allocator for
the driver (i.e., instead of malloc() or operator new) and debug
any driver issues. We would probably want to be able to control
this facility using some environment variable in addition to
the function argument so that by simply setting the environment
we could enable strict checking without having to recompile any
files.

Btw., if you haven't yet, you might want to take a look at the code
in src/memattr.cpp and tests/src/new.cpp. You might it helpful in
working on this (e.g., rw_free() shouldn't crash even when passed
an invalid pointer or a valid pointer to a corrupt chunk of memory).

Martin

Mime
View raw message