I have compiled wget as a dll and trying to use it my code.I seem to get
an access violation in DO_REALLOC_FROM_ALLOCA in the memcpy call when
the call is made in the following order
convert_and_copy(html-parse.c)->POOL_APPEND->POOL_GROW->DO_REALLOC_FROM_ALLOCA
on taking a closer look at the code in DO_REALLOC_FROM_ALLOCA
#define DO_REALLOC_FROM_ALLOCA(basevar, sizevar, needed_size, allocap,
type) do \
{ \
/* Avoid side-effectualness. */ \
long do_realloc_needed_size = (needed_size); \
long do_realloc_newsize = 0; \
while ((sizevar) < (do_realloc_needed_size)) { \
do_realloc_newsize = 2*(sizevar); \
if (do_realloc_newsize < 16) \
do_realloc_newsize = 16; \
(sizevar) = do_realloc_newsize; \
} \
if (do_realloc_newsize) \
{ \
if (!allocap) \
XREALLOC_ARRAY (basevar, type, do_realloc_newsize); \
else \
{ \
void *drfa_new_basevar = xmalloc (do_realloc_newsize); \
memcpy (drfa_new_basevar, basevar, sizevar); \
(basevar) = drfa_new_basevar; \
allocap = 0; \
} \
} \
} while (0)
Here
void *drfa_new_basevar = xmalloc (do_realloc_newsize); \
memcpy (drfa_new_basevar, basevar, sizevar); \
we are trying to copy sizevar bytes of basevar to drfa_new_basevar.One
thing to notice here is basevar is not of size
sizevar now since we have incremented sizevar to a newsize.
basevar is of size lower than that.So normally when we try to copy we
are trying to read from memory(outside basevar).and in the process ,an
access vilation is generated
Fortunately when it is a standalone program may be we get away with it
.But when it is built as a dll which has to share the process space with
other dlls, it gets caught
Is my assumption right?
How do we solve this
Regards
Bharath