Re: memset (0, 0, 0);

Petr Vandrovec
2003-04-04T16:12:36Z

On 4 Apr 03 at 17:21, Andreas Schwab wrote:
> Joern Rennecke <joern.rennecke@superh.com> writes:
>
> |> So, as i understand this, this means that the first argument of memset
> |> must point to an object, which contains at least one (the first)
> |> character. Passing a NULL pointer, or any other address which is
> |> outside the address space of the program, invokes undefined behaviour.

But it is completely safe to call memset with unaligned pointer. Your
word read will do bad things in such situation (either you'll read memory
before object, or you'll read memory after object - first can cause
unexpected behavior, second can cause crash).

And it must not modify area outside of specified range, so please make sure
that

volatile unsigned int ptr;
memset(&ptr, 0, 0);

does not do any write at &ptr. I think that even reading from &ptr is
unexpected side effect...

BTW, all functions I know handle NULL, 0 without crash - being it
read, write, recvfrom (for both data & address), or current
implementation of memset, memcpy.
Petr Vandrovec