At 02:39 even 9/30/02 -0700, Satya wrote:
Classic buffer overflow. Say you have[...]:
buffer over flow is defined as when you feed more data than the buffer has
[free] capacity for. Due to the C legacy which does not do bound checking
for array writes this may lead to to bad places. Agreed. But when you
malloc you allocate /limited/ memory too. There is /no/ way to prevent you
from overflowing an allocated buffer if you so wish.
Even if you do bounds checking, you'll have a
limited input condition.
yeah, if you allocate 64 bytes (I like 2^n - aligns well), say, then you
/do/ have a limit.
[..C for dummies example]
But it's safest to malloc and realloc, because then you're only limited by
how much memory the OS is willing to give you.
to malloc or not to malloc is the question. ummmm... Malloc allows you to
have sophisticated mechanisms where you may limit size of buffer to only
the size of free memory available from the OS. I seem to remember
someplace that realloc should be avoided as it is highly
inefficient. Someone else can have a say on this maybe. For truly
flexible storage a linked lists of buffers may be more the way to go.