Fixes undefined behavior and segfault
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 8edc17b639c4ac47913c467107ffb43c67c64890)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -75,17 +75,20 @@ static av_cold int encode_init(AVCodecContext *avctx) |
75 | 75 |
return 0; |
76 | 76 |
} |
77 | 77 |
|
78 |
-#define write16(p, value) \ |
|
79 |
-do { \ |
|
80 |
- if (s->big_endian) AV_WB16(p, value); \ |
|
81 |
- else AV_WL16(p, value); \ |
|
82 |
-} while(0) |
|
78 |
+static av_always_inline void write16_internal(int big_endian, void *p, int value) |
|
79 |
+{ |
|
80 |
+ if (big_endian) AV_WB16(p, value); |
|
81 |
+ else AV_WL16(p, value); |
|
82 |
+} |
|
83 |
+ |
|
84 |
+static av_always_inline void write32_internal(int big_endian, void *p, int value) |
|
85 |
+{ |
|
86 |
+ if (big_endian) AV_WB32(p, value); |
|
87 |
+ else AV_WL32(p, value); |
|
88 |
+} |
|
83 | 89 |
|
84 |
-#define write32(p, value) \ |
|
85 |
-do { \ |
|
86 |
- if (s->big_endian) AV_WB32(p, value); \ |
|
87 |
- else AV_WL32(p, value); \ |
|
88 |
-} while(0) |
|
90 |
+#define write16(p, value) write16_internal(s->big_endian, p, value) |
|
91 |
+#define write32(p, value) write32_internal(s->big_endian, p, value) |
|
89 | 92 |
|
90 | 93 |
static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic, uint8_t *dst) |
91 | 94 |
{ |