Re: Out-of-bounds nonsense
- From: "Herbert Rosenau" <os2guy@xxxxxxxxxxxxx>
- Date: Fri, 3 Nov 2006 12:44:07 +0000 (UTC)
On Thu, 2 Nov 2006 18:32:21 UTC, Frederick Gotham <fgothamNO@xxxxxxxx>
wrote:
Roberto Waltman:May result in udefined behavior when Type1 != Type2 as the
Not so:
/* in a system where sizeof long is 4 */
long obj1;
char obj2;
/* UB: attempts to copy 3 chars past obj2 */
memcpy(&obj1,&obj2,sizeof obj1);
Of course, you're right.
Type1 obj1;
Type2 obj2;
if (sizeof obj2 >= sizeof obj1)
memcpy(&obj1,&obj2,sizeof obj1);
representation of different types does not require that they are have
to have the same padding bits adn/or alignment requirements. memcpy
can fail in the lands of udefined behavior here. Accessing obje1
thereafter can end in anything but may not do what you thinks it
should do.
--
Tschau/Bye
Herbert
Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
.
- Follow-Ups:
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Flash Gordon
- Re: Out-of-bounds nonsense
- References:
- Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Pierre Asselin
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Chris Dollin
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Mark McIntyre
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Flash Gordon
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Richard Heathfield
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Roberto Waltman
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Out-of-bounds nonsense
- Prev by Date: Re: Cannot return values of char variable
- Next by Date: Re: comparing ptrs/mmap
- Previous by thread: Re: Out-of-bounds nonsense
- Next by thread: Re: Out-of-bounds nonsense
- Index(es):
Relevant Pages
|
|