[FFmpeg-devel] [PATCH] all: silence clang -Wabsolute-value for unsigned subtractions

Ganesh Ajjanagadde gajjanag at mit.edu
Mon Aug 24 01:22:54 CEST 2015


On Sun, Aug 23, 2015 at 6:58 PM, Michael Niedermayer
<michael at niedermayer.cc> wrote:
> On Sat, Aug 22, 2015 at 04:26:53PM +0200, Nicolas George wrote:
>> 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
>> behaviour.
>
> i dont know what "morally negative" means exactly but convertion
> of out of range values to signed integers is not undefined behavior
> in C. It is implementation defined or raises a implementation defined
> signal
> Please see 6.3.1.3 Signed and unsigned integers in ISO/IEC 9899:TC3
>
> I doubt that FFmpeg will work on platforms that
> define this significantly differently than how it is defined for the
> currently supported platforms,

You are right that all standard platforms do this, which is why we
never had a bug.
However, we can achieve compliance with no cost with the patchv2.
Maybe the macro/casts are ugly,
but I currently treat standards compliance (minimal reliance on
implementation defined behavior) as most important.

>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The real ebay dictionary, page 3
> "Rare item" - "Common item with rare defect or maybe just a lie"
> "Professional" - "'Toy' made in china, not functional except as doorstop"
> "Experts will know" - "The seller hopes you are not an expert"
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list