[FFmpeg-devel] [PATCH] all: silence clang -Wabsolute-value for unsigned subtractions
george at nsup.org
Sat Aug 22 16:26:53 CEST 2015
Le quintidi 5 fructidor, an CCXXIII, Ganesh Ajjanagadde a écrit :
> + /* cast for -Wabsolute-value in clang 3.5+ */
> + return abs((int) (t1 - t2)) + abs((int) ((c1 & 0x000000ff) - (c2 & 0x000000ff))) +
> + abs((int) (((c1 & 0x0000ff00) >> 8) - ((c2 & 0x0000ff00) >> 8))) +
> + abs((int) (((c1 & 0x00ff0000) >> 16) - ((c2 & 0x00ff0000) >> 16)));
I believe this is not correct, with or without the cast (the cast is
implicit due to the prototype of abs(), of course): if the result is morally
negative, converting the morally-negative unsigned to signed is an undefined
The correct fix would probably be "abs((int)x - (int)y)". Hopefully, the
compiler will generate the exact same code. A macro absdiff() would probably
make things more readable.
Not that you did not introduce the undefined behaviour. You just noticed it
with that new warning.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: Digital signature
More information about the ffmpeg-devel