Message ID | 20200825140927.16433-17-andreas.rheinhardt@gmail.com |
---|---|
State | Accepted |
Commit | e07541930a8a045f1924152e12f8615043480b6f |
Headers | show |
Series | [FFmpeg-devel,01/19] avfilter/avfilter: Fix indentation | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On 8/25/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote: > The signature filter uses qsort, but its compare function doesn't have > the signature required of such a function; therefore it casts the function > pointer to void. Yet this is wrong: > C90 only guarantees that one can convert a pointer to any incomplete > type or object type to void* and back with the result comparing equal > to the original which makes pointers to void generic pointers to > incomplete or object type. Yet C90 lacks a generic function pointer > type. > C99 additionally guarantees that a pointer to a function of one type may > be converted to a pointer to a function of another type with the result > and the original comparing equal when converting back. > This makes any function pointer type a generic function pointer type. > Yet even this does not make pointers to void generic function pointers. > > Both GCC and Clang emit warnings for this when in pedantic mode. > > This commit fixes this by modifying the compare function to comply with > the expected signature. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavfilter/vf_signature.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > LGTM > diff --git a/libavfilter/vf_signature.c b/libavfilter/vf_signature.c > index 80957d0047..32a6405e14 100644 > --- a/libavfilter/vf_signature.c > +++ b/libavfilter/vf_signature.c > @@ -132,8 +132,9 @@ static uint64_t get_block_sum(StreamContext *sc, > uint64_t intpic[32][32], const > return sum; > } > > -static int cmp(const uint64_t *a, const uint64_t *b) > +static int cmp(const void *x, const void *y) > { > + const uint64_t *a = x, *b = y; > return *a < *b ? -1 : ( *a > *b ? 1 : 0 ); > } > > @@ -291,7 +292,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame > *picref) > } > > /* get threshold */ > - qsort(sortsignature, elemcat->elem_count, sizeof(uint64_t), (void*) > cmp); > + qsort(sortsignature, elemcat->elem_count, sizeof(uint64_t), cmp); > th = sortsignature[(int) (elemcat->elem_count*0.333)]; > > /* ternarize */ > @@ -317,7 +318,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame > *picref) > } > > /* confidence */ > - qsort(conflist, DIFFELEM_SIZE, sizeof(uint64_t), (void*) cmp); > + qsort(conflist, DIFFELEM_SIZE, sizeof(uint64_t), cmp); > fs->confidence = FFMIN(conflist[DIFFELEM_SIZE/2], 255); > > /* coarsesignature */ > -- > 2.20.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/libavfilter/vf_signature.c b/libavfilter/vf_signature.c index 80957d0047..32a6405e14 100644 --- a/libavfilter/vf_signature.c +++ b/libavfilter/vf_signature.c @@ -132,8 +132,9 @@ static uint64_t get_block_sum(StreamContext *sc, uint64_t intpic[32][32], const return sum; } -static int cmp(const uint64_t *a, const uint64_t *b) +static int cmp(const void *x, const void *y) { + const uint64_t *a = x, *b = y; return *a < *b ? -1 : ( *a > *b ? 1 : 0 ); } @@ -291,7 +292,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) } /* get threshold */ - qsort(sortsignature, elemcat->elem_count, sizeof(uint64_t), (void*) cmp); + qsort(sortsignature, elemcat->elem_count, sizeof(uint64_t), cmp); th = sortsignature[(int) (elemcat->elem_count*0.333)]; /* ternarize */ @@ -317,7 +318,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) } /* confidence */ - qsort(conflist, DIFFELEM_SIZE, sizeof(uint64_t), (void*) cmp); + qsort(conflist, DIFFELEM_SIZE, sizeof(uint64_t), cmp); fs->confidence = FFMIN(conflist[DIFFELEM_SIZE/2], 255); /* coarsesignature */
The signature filter uses qsort, but its compare function doesn't have the signature required of such a function; therefore it casts the function pointer to void. Yet this is wrong: C90 only guarantees that one can convert a pointer to any incomplete type or object type to void* and back with the result comparing equal to the original which makes pointers to void generic pointers to incomplete or object type. Yet C90 lacks a generic function pointer type. C99 additionally guarantees that a pointer to a function of one type may be converted to a pointer to a function of another type with the result and the original comparing equal when converting back. This makes any function pointer type a generic function pointer type. Yet even this does not make pointers to void generic function pointers. Both GCC and Clang emit warnings for this when in pedantic mode. This commit fixes this by modifying the compare function to comply with the expected signature. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavfilter/vf_signature.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)