[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: RE : [cobalt-developers] Help: error when reading a file with C++



>If I declare the char * buf before calling open(...), it runs.
>Else if I declare char * buf = new char after calling open(...), it
runs
>so.

>It seems strange, no ?

Not strange at all, what you've just coded is a buffer overflow waiting
to happen.

You will need to use new/malloc to allocate the memory for the "char"
you are pointing buf towards. Or define buf in a way that allocates
space for it, instead of space for a pointer.

ChrisB.