This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: memset (0, 0, 0);
- From: "Petr Vandrovec" <VANDROVE at vc dot cvut dot cz>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: sean dot mcgoogan at superh dot com, bug-glibc at gnu dot org,stephen dot thomas at superh dot com, newlib at sources dot redhat dot com,gdb at sources dot redhat dot com
- Date: Fri, 4 Apr 2003 18:12:21 +0200
- Subject: Re: memset (0, 0, 0);
- Organization: CC CTU Prague
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