[Ffmpeg-devel] [PATCH] avoid useless memcpy with src==dst (valgrind complains)

Måns Rullgård mru
Sun Jul 23 22:20:50 CEST 2006


Rich Felker said:
> On Sun, Jul 23, 2006 at 05:35:59PM +0200, Reimar D?ffinger wrote:
>> Hello,
>> On Sun, Jul 23, 2006 at 02:24:17PM -0000, Wolfram Gloger wrote:
>> > > Though for src == dst I doubt any memcpy function will break
>> > > stuff. And for the overlapping case when src != dst does the C standard
>> > > specify the behaviour?
>> >
>> > Using memcpy() on overlapping objects is undefined behaviour
>> > (7.21.2.1#2).
>>
>> Which part were you replying to? If to the first: memcpy may strictly
>> speaking have undefined behaviour for src == dst, but I very much doubt
>> it has in reality.
>> If to the second part: I meant if you have two "struct something"
>> pointers a and b, is the behaviour of *a = *b defined when the areas for
>> *a and *b overlap?
>
> That's an interesting question. *a = *b may be undefined when a and b
> both point to the same object; I'm not sure. Anyone care to dig up
> this info?

The objects must overlap exactly or not at all. Otherwise the result is
undefined.

-- 
M?ns Rullg?rd
mru at inprovide.com




More information about the ffmpeg-devel mailing list