Skip to content

Commit 10d1be2

Browse files
committed
swscale/internal: use static_assert for enforcing offsets
Instead of sprinkling av_assert0 into random init functions. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas <[email protected]>
1 parent 55d5eae commit 10d1be2

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

libswscale/swscale_internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define SWSCALE_SWSCALE_INTERNAL_H
2323

2424
#include <stdatomic.h>
25+
#include <assert.h>
2526

2627
#include "config.h"
2728
#include "swscale.h"
@@ -705,6 +706,16 @@ struct SwsInternal {
705706
};
706707
//FIXME check init (where 0)
707708

709+
static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32),
710+
"dither32 must be at the same offset as redDither + DITHER32_INT");
711+
712+
#if ARCH_X86_64
713+
/* x86 yuv2gbrp uses the SwsInternal for yuv coefficients
714+
if struct offsets change the asm needs to be updated too */
715+
static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292,
716+
"yuv2rgb_y_offset must be updated in x86 asm");
717+
#endif
718+
708719
SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c);
709720
int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4],
710721
int fullRange, int brightness,

libswscale/utils.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,6 @@ SwsContext *sws_alloc_context(void)
12281228
{
12291229
SwsInternal *c = av_mallocz(sizeof(SwsInternal));
12301230

1231-
av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32));
1232-
12331231
if (c) {
12341232
c->av_class = &ff_sws_context_class;
12351233
av_opt_set_defaults(c);

libswscale/x86/swscale.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,6 @@ switch(c->dstBpc){ \
791791

792792
if(c->flags & SWS_FULL_CHR_H_INT) {
793793

794-
/* yuv2gbrp uses the SwsInternal for yuv coefficients
795-
if struct offsets change the asm needs to be updated too */
796-
av_assert0(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292);
797-
798794
#define YUV2ANYX_FUNC_CASE(fmt, name, opt) \
799795
case fmt: \
800796
c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \

0 commit comments

Comments
 (0)