This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: memset (0, 0, 0);


On  4 Apr 03 at 17:21, Andreas Schwab wrote:
> Joern Rennecke <joern dot rennecke at superh dot 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
                                            


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]