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

Wolfram Gloger wmglo
Sun Jul 23 16:24:17 CEST 2006


> On Sun, Jul 23, 2006 at 11:07:42AM +0100, M?ns Rullg?rd wrote:
> > > Huh? The problem is the assignment is obviously replaced by a memcpy by the
> > > compiler,
> > 
> > Depends on the struct.  For small structs the compiler will generate
> > load/store insns directly, and it can use knowledge of alignment to  optimize
> > things.
> Well, gcc 4.1.1 in this cases uses an memcpy.

Well, my gcc-4.1.1 doesn't:

gcc version 4.1.1 20060511 (prerelease) (Debian 4.1.0-4)

I cannot find any memcpy in the generated assembly for
avcodec_default_release_buffer (double-checked).

> > If the compiler does that it's broken.
> Maybe.

Not maybe, definitely!

> 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

> Anyway, this is not really what interests me, I'd prefer to know that
> even if it is a compiler bug, may I apply the patch or do you prefer if
> I don't?

Patch looks fine to me anyway, but I think it should be investigated
how on earth memcpy() is generated here.


More information about the ffmpeg-devel mailing list