Bug Summary

File:root/firefox-clang/media/ffvpx/libavcodec/put_bits.h
Warning:line 236, column 29
The result of right shift is undefined because the right operand is negative

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name aac_adtstoasc.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -include libavutil_visibility.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_AV_CONFIG_H -D ASSERT_LEVEL=2 -I /root/firefox-clang/media/ffvpx/libavcodec/bsf -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -I /root/firefox-clang/media/ffvpx/libavcodec -I /root/firefox-clang/media/ffvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-parentheses -Wno-pointer-sign -Wno-sign-compare -Wno-switch -Wno-type-limits -Wno-unused-function -Wno-deprecated-declarations -Wno-absolute-value -Wno-incompatible-pointer-types -Wno-string-conversion -Wno-visibility -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/media/ffvpx/libavcodec/bsf/aac_adtstoasc.c

/root/firefox-clang/media/ffvpx/libavcodec/bsf/aac_adtstoasc.c

1/*
2 * MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
3 * Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "adts_header.h"
23#include "adts_parser.h"
24#include "bsf.h"
25#include "bsf_internal.h"
26#include "put_bits.h"
27#include "get_bits.h"
28#include "mpeg4audio.h"
29#include "mpeg4audio_copy_pce.h"
30
31typedef struct AACBSFContext {
32 int first_frame_done;
33} AACBSFContext;
34
35/**
36 * This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
37 * ADTS header and removes the ADTS header.
38 */
39static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt)
40{
41 AACBSFContext *ctx = bsfc->priv_data;
42
43 PutBitContext pb;
44 AACADTSHeaderInfo hdr;
45 int ret;
46
47 ret = ff_bsf_get_packet_ref(bsfc, pkt);
48 if (ret < 0)
1
Assuming 'ret' is >= 0
49 return ret;
50
51 if (bsfc->par_in->extradata && pkt->size >= 2 && (AV_RB16(pkt->data)av_bswap16((((const union unaligned_16 *) (pkt->data))->
l))
>> 4) != 0xfff)
2
Assuming field 'extradata' is null
52 return 0;
53
54 if (pkt->size < AV_AAC_ADTS_HEADER_SIZE7)
3
Assuming field 'size' is >= AV_AAC_ADTS_HEADER_SIZE
4
Taking false branch
55 goto packet_too_small;
56
57 if (ff_adts_header_parse_buf(pkt->data, &hdr) < 0) {
5
Assuming the condition is false
58 av_log(bsfc, AV_LOG_ERROR16, "Error parsing ADTS frame header!\n");
59 ret = AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
60 goto fail;
61 }
62
63 if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
6
Assuming field 'crc_absent' is not equal to 0
64 avpriv_report_missing_feature(bsfc,
65 "Multiple RDBs per frame with CRC");
66 ret = AVERROR_PATCHWELCOME(-(int)(('P') | (('A') << 8) | (('W') << 16) | ((
unsigned)('E') << 24)))
;
67 goto fail;
68 }
69
70 pkt->size -= AV_AAC_ADTS_HEADER_SIZE7 + 2 * !hdr.crc_absent
6.1
Field 'crc_absent' is not equal to 0
6.1
Field 'crc_absent' is not equal to 0
6.1
Field 'crc_absent' is not equal to 0
;
71 if (pkt->size <= 0)
7
Assuming field 'size' is > 0
8
Taking false branch
72 goto packet_too_small;
73 pkt->data += AV_AAC_ADTS_HEADER_SIZE7 + 2 * !hdr.crc_absent
8.1
Field 'crc_absent' is not equal to 0
8.1
Field 'crc_absent' is not equal to 0
8.1
Field 'crc_absent' is not equal to 0
;
74
75 if (!ctx->first_frame_done) {
9
Assuming field 'first_frame_done' is 0
10
Taking true branch
76 int pce_size = 0;
77 uint8_t pce_data[MAX_PCE_SIZE320];
78 uint8_t *extradata;
79
80 if (!hdr.chan_config) {
11
Assuming field 'chan_config' is 0
12
Taking true branch
81 GetBitContext gb;
82 init_get_bits(&gb, pkt->data, pkt->size * 8);
83 if (get_bits(&gb, 3) != 5) {
13
Assuming the condition is false
14
Taking false branch
84 avpriv_report_missing_feature(bsfc,
85 "PCE-based channel configuration "
86 "without PCE as first syntax "
87 "element");
88 ret = AVERROR_PATCHWELCOME(-(int)(('P') | (('A') << 8) | (('W') << 16) | ((
unsigned)('E') << 24)))
;
89 goto fail;
90 }
91 init_put_bits(&pb, pce_data, MAX_PCE_SIZE320);
92 pce_size = ff_copy_pce_data(&pb, &gb) / 8;
15
Calling 'ff_copy_pce_data'
93 flush_put_bits(&pb);
94 pkt->size -= get_bits_count(&gb)/8;
95 pkt->data += get_bits_count(&gb)/8;
96 }
97
98 extradata = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
99 2 + pce_size);
100 if (!extradata) {
101 ret = AVERROR(ENOMEM)(-(12));
102 goto fail;
103 }
104
105 init_put_bits(&pb, extradata, 2 + pce_size);
106 put_bits(&pb, 5, hdr.object_type);
107 put_bits(&pb, 4, hdr.sampling_index);
108 put_bits(&pb, 4, hdr.chan_config);
109 put_bits(&pb, 1, 0); //frame length - 1024 samples
110 put_bits(&pb, 1, 0); //does not depend on core coder
111 put_bits(&pb, 1, 0); //is not extension
112 flush_put_bits(&pb);
113 if (pce_size) {
114 memcpy(extradata + 2, pce_data, pce_size);
115 }
116
117 ctx->first_frame_done = 1;
118 }
119
120 return 0;
121
122packet_too_small:
123 av_log(bsfc, AV_LOG_ERROR16, "Input packet too small\n");
124 ret = AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
125fail:
126 av_packet_unref(pkt);
127 return ret;
128}
129
130static int aac_adtstoasc_init(AVBSFContext *ctx)
131{
132 /* Validate the extradata if the stream is already MPEG-4 AudioSpecificConfig */
133 if (ctx->par_in->extradata) {
134 MPEG4AudioConfig mp4ac;
135 int ret = avpriv_mpeg4audio_get_config2(&mp4ac, ctx->par_in->extradata,
136 ctx->par_in->extradata_size, 1, ctx);
137 if (ret < 0) {
138 av_log(ctx, AV_LOG_ERROR16, "Error parsing AudioSpecificConfig extradata!\n");
139 return ret;
140 }
141 }
142
143 return 0;
144}
145
146static const enum AVCodecID codec_ids[] = {
147 AV_CODEC_ID_AAC, AV_CODEC_ID_NONE,
148};
149
150const FFBitStreamFilter ff_aac_adtstoasc_bsf = {
151 .p.name = "aac_adtstoasc",
152 .p.codec_ids = codec_ids,
153 .priv_data_size = sizeof(AACBSFContext),
154 .init = aac_adtstoasc_init,
155 .filter = aac_adtstoasc_filter,
156};

/root/firefox-clang/media/ffvpx/libavcodec/mpeg4audio_copy_pce.h

1/*
2 * MPEG-4 Audio PCE copying function
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVCODEC_MPEG4AUDIO_COPY_PCE_H
22#define AVCODEC_MPEG4AUDIO_COPY_PCE_H
23
24#include "libavutil/attributes.h"
25
26#include "get_bits.h"
27#include "put_bits.h"
28
29static av_always_inline__attribute__((always_inline)) inline unsigned int ff_pce_copy_bits(PutBitContext *pb,
30 GetBitContext *gb,
31 int bits)
32{
33 unsigned int el = get_bits(gb, bits);
34 put_bits(pb, bits, el);
35 return el;
36}
37
38static inline int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
39{
40 int five_bit_ch, four_bit_ch, comment_size, bits;
41 int offset = put_bits_count(pb);
42
43 ff_pce_copy_bits(pb, gb, 10); // Tag, Object Type, Frequency
44 five_bit_ch = ff_pce_copy_bits(pb, gb, 4); // Front
45 five_bit_ch += ff_pce_copy_bits(pb, gb, 4); // Side
46 five_bit_ch += ff_pce_copy_bits(pb, gb, 4); // Back
47 four_bit_ch = ff_pce_copy_bits(pb, gb, 2); // LFE
48 four_bit_ch += ff_pce_copy_bits(pb, gb, 3); // Data
49 five_bit_ch += ff_pce_copy_bits(pb, gb, 4); // Coupling
50 if (ff_pce_copy_bits(pb, gb, 1)) // Mono Mixdown
16
Assuming the condition is false
17
Taking false branch
51 ff_pce_copy_bits(pb, gb, 4);
52 if (ff_pce_copy_bits(pb, gb, 1)) // Stereo Mixdown
18
Assuming the condition is false
19
Taking false branch
53 ff_pce_copy_bits(pb, gb, 4);
54 if (ff_pce_copy_bits(pb, gb, 1)) // Matrix Mixdown
20
Assuming the condition is false
21
Taking false branch
55 ff_pce_copy_bits(pb, gb, 3);
56 for (bits = five_bit_ch*5+four_bit_ch*4; bits > 16; bits -= 16)
22
Assuming 'bits' is <= 16
23
Loop condition is false. Execution continues on line 58
57 ff_pce_copy_bits(pb, gb, 16);
58 if (bits)
24
Assuming 'bits' is not equal to 0
25
Taking true branch
59 ff_pce_copy_bits(pb, gb, bits);
60 align_put_bits(pb);
26
Calling 'align_put_bits'
61 align_get_bits(gb);
62 comment_size = ff_pce_copy_bits(pb, gb, 8);
63 for (; comment_size > 0; comment_size--)
64 ff_pce_copy_bits(pb, gb, 8);
65
66 return put_bits_count(pb) - offset;
67}
68
69#endif /* AVCODEC_MPEG4AUDIO_COPY_PCE_H */

/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h

1/*
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * bitstream writer API
24 */
25
26#ifndef AVCODEC_PUT_BITS_H
27#define AVCODEC_PUT_BITS_H
28
29#include <stdint.h>
30#include <stddef.h>
31
32#include "config.h"
33#include "libavutil/intreadwrite.h"
34#include "libavutil/avassert.h"
35#include "libavutil/common.h"
36
37#if ARCH_X86_641
38// TODO: Benchmark and optionally enable on other 64-bit architectures.
39typedef uint64_t BitBuf;
40#define AV_WBBUF AV_WB64
41#define AV_WLBUF AV_WL64
42#define BUF_BITS64 64
43#else
44typedef uint32_t BitBuf;
45#define AV_WBBUF AV_WB32
46#define AV_WLBUF AV_WL32
47#define BUF_BITS64 32
48#endif
49
50typedef struct PutBitContext {
51 BitBuf bit_buf;
52 int bit_left;
53 uint8_t *buf, *buf_ptr, *buf_end;
54} PutBitContext;
55
56/**
57 * Initialize the PutBitContext s.
58 *
59 * @param buffer the buffer where to put bits
60 * @param buffer_size the size in bytes of buffer
61 */
62static inline void init_put_bits(PutBitContext *s, uint8_t *buffer,
63 int buffer_size)
64{
65 if (buffer_size < 0) {
66 buffer_size = 0;
67 buffer = NULL((void*)0);
68 }
69
70 s->buf = buffer;
71 s->buf_end = s->buf + buffer_size;
72 s->buf_ptr = s->buf;
73 s->bit_left = BUF_BITS64;
74 s->bit_buf = 0;
75}
76
77/**
78 * Inform the compiler that a PutBitContext is flushed (i.e. if it has just
79 * been initialized or flushed). Undefined behaviour occurs if this is used
80 * with a PutBitContext for which this is not true.
81 */
82static inline void put_bits_assume_flushed(const PutBitContext *s)
83{
84 av_assume(s->bit_left == BUF_BITS)do { if (!(s->bit_left == 64)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "s->bit_left == 64", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 84); abort(); } } while (0)
;
85}
86
87/**
88 * @return the total number of bits written to the bitstream.
89 */
90static inline int put_bits_count(PutBitContext *s)
91{
92 return (s->buf_ptr - s->buf) * 8 + BUF_BITS64 - s->bit_left;
93}
94
95/**
96 * @return the number of bytes output so far; may only be called
97 * when the PutBitContext is freshly initialized or flushed.
98 */
99static inline int put_bytes_output(const PutBitContext *s)
100{
101 av_assert2(s->bit_left == BUF_BITS)do { if (!(s->bit_left == 64)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "s->bit_left == 64", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 101); abort(); } } while (0)
;
102 return s->buf_ptr - s->buf;
103}
104
105/**
106 * @param round_up When set, the number of bits written so far will be
107 * rounded up to the next byte.
108 * @return the number of bytes output so far.
109 */
110static inline int put_bytes_count(const PutBitContext *s, int round_up)
111{
112 return s->buf_ptr - s->buf + ((BUF_BITS64 - s->bit_left + (round_up ? 7 : 0)) >> 3);
113}
114
115/**
116 * Rebase the bit writer onto a reallocated buffer.
117 *
118 * @param buffer the buffer where to put bits
119 * @param buffer_size the size in bytes of buffer,
120 * must be large enough to hold everything written so far
121 */
122static inline void rebase_put_bits(PutBitContext *s, uint8_t *buffer,
123 int buffer_size)
124{
125 av_assert0(8*buffer_size >= put_bits_count(s))do { if (!(8*buffer_size >= put_bits_count(s))) { av_log((
(void*)0), 0, "Assertion %s failed at %s:%d\n", "8*buffer_size >= put_bits_count(s)"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 125
); abort(); } } while (0)
;
126
127 s->buf_end = buffer + buffer_size;
128 s->buf_ptr = buffer + (s->buf_ptr - s->buf);
129 s->buf = buffer;
130}
131
132/**
133 * @return the number of bits available in the bitstream.
134 */
135static inline int put_bits_left(PutBitContext* s)
136{
137 return (s->buf_end - s->buf_ptr) * 8 - BUF_BITS64 + s->bit_left;
138}
139
140/**
141 * @param round_up When set, the number of bits written will be
142 * rounded up to the next byte.
143 * @return the number of bytes left.
144 */
145static inline int put_bytes_left(const PutBitContext *s, int round_up)
146{
147 return s->buf_end - s->buf_ptr - ((BUF_BITS64 - s->bit_left + (round_up ? 7 : 0)) >> 3);
148}
149
150/**
151 * Pad the end of the output stream with zeros.
152 */
153static inline void flush_put_bits(PutBitContext *s)
154{
155#ifndef BITSTREAM_WRITER_LE
156 if (s->bit_left < BUF_BITS64)
157 s->bit_buf <<= s->bit_left;
158#endif
159 while (s->bit_left < BUF_BITS64) {
160 av_assert0(s->buf_ptr < s->buf_end)do { if (!(s->buf_ptr < s->buf_end)) { av_log(((void
*)0), 0, "Assertion %s failed at %s:%d\n", "s->buf_ptr < s->buf_end"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 160
); abort(); } } while (0)
;
161#ifdef BITSTREAM_WRITER_LE
162 *s->buf_ptr++ = s->bit_buf;
163 s->bit_buf >>= 8;
164#else
165 *s->buf_ptr++ = s->bit_buf >> (BUF_BITS64 - 8);
166 s->bit_buf <<= 8;
167#endif
168 s->bit_left += 8;
169 }
170 s->bit_left = BUF_BITS64;
171 s->bit_buf = 0;
172}
173
174static inline void flush_put_bits_le(PutBitContext *s)
175{
176 while (s->bit_left < BUF_BITS64) {
177 av_assert0(s->buf_ptr < s->buf_end)do { if (!(s->buf_ptr < s->buf_end)) { av_log(((void
*)0), 0, "Assertion %s failed at %s:%d\n", "s->buf_ptr < s->buf_end"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 177
); abort(); } } while (0)
;
178 *s->buf_ptr++ = s->bit_buf;
179 s->bit_buf >>= 8;
180 s->bit_left += 8;
181 }
182 s->bit_left = BUF_BITS64;
183 s->bit_buf = 0;
184}
185
186#ifdef BITSTREAM_WRITER_LE
187#define ff_put_string ff_put_string_unsupported_here
188#define ff_copy_bits ff_copy_bits_unsupported_here
189#else
190
191/**
192 * Put the string string in the bitstream.
193 *
194 * @param terminate_string 0-terminates the written string if value is 1
195 */
196void ff_put_string(PutBitContext *pb, const char *string,
197 int terminate_string);
198
199/**
200 * Copy the content of src to the bitstream.
201 *
202 * @param length the number of bits of src to copy
203 */
204void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
205#endif
206
207static inline void put_bits_no_assert(PutBitContext *s, int n, BitBuf value)
208{
209 BitBuf bit_buf;
210 int bit_left;
211
212 bit_buf = s->bit_buf;
213 bit_left = s->bit_left;
214
215 /* XXX: optimize */
216#ifdef BITSTREAM_WRITER_LE
217 bit_buf |= value << (BUF_BITS64 - bit_left);
218 if (n >= bit_left) {
219 if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
220 AV_WLBUF(s->buf_ptr, bit_buf);
221 s->buf_ptr += sizeof(BitBuf);
222 } else {
223 av_log(NULL((void*)0), AV_LOG_ERROR16, "Internal error, put_bits buffer too small\n");
224 av_assert2(0)do { if (!(0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "0", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 224); abort(); } } while (0)
;
225 }
226 bit_buf = value >> bit_left;
227 bit_left += BUF_BITS64;
228 }
229 bit_left -= n;
230#else
231 if (n < bit_left) {
35
Assuming 'n' is >= 'bit_left'
36
Taking false branch
232 bit_buf = (bit_buf << n) | value;
233 bit_left -= n;
234 } else {
235 bit_buf <<= bit_left;
236 bit_buf |= value >> (n - bit_left);
37
The result of right shift is undefined because the right operand is negative
237 if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
238 AV_WBBUF(s->buf_ptr, bit_buf);
239 s->buf_ptr += sizeof(BitBuf);
240 } else {
241 av_log(NULL((void*)0), AV_LOG_ERROR16, "Internal error, put_bits buffer too small\n");
242 av_assert2(0)do { if (!(0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "0", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 242); abort(); } } while (0)
;
243 }
244 bit_left += BUF_BITS64 - n;
245 bit_buf = value;
246 }
247#endif
248
249 s->bit_buf = bit_buf;
250 s->bit_left = bit_left;
251}
252
253/**
254 * Write up to 31 bits into a bitstream.
255 * Use put_bits32 to write 32 bits.
256 */
257static inline void put_bits(PutBitContext *s, int n, BitBuf value)
258{
259 av_assert2(n <= 31 && value < (BitBuf)(1U << n))do { if (!(n <= 31 && value < (BitBuf)(1U <<
n))) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "n <= 31 && value < (BitBuf)(1U << n)",
"/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 259
); abort(); } } while (0)
;
29
Assuming 'n' is <= 31
30
Assuming the condition is true
31
Taking false branch
32
Loop condition is false. Exiting loop
260 put_bits_no_assert(s, n, value);
33
Passing the value 0 via 3rd parameter 'value'
34
Calling 'put_bits_no_assert'
261}
262
263static inline void put_bits_le(PutBitContext *s, int n, BitBuf value)
264{
265 BitBuf bit_buf;
266 int bit_left;
267
268 av_assert2(n <= 31 && value < (BitBuf)(1U << n))do { if (!(n <= 31 && value < (BitBuf)(1U <<
n))) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "n <= 31 && value < (BitBuf)(1U << n)",
"/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 268
); abort(); } } while (0)
;
269
270 bit_buf = s->bit_buf;
271 bit_left = s->bit_left;
272
273 bit_buf |= value << (BUF_BITS64 - bit_left);
274 if (n >= bit_left) {
275 if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
276 AV_WLBUF(s->buf_ptr, bit_buf);
277 s->buf_ptr += sizeof(BitBuf);
278 } else {
279 av_log(NULL((void*)0), AV_LOG_ERROR16, "Internal error, put_bits buffer too small\n");
280 av_assert2(0)do { if (!(0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "0", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 280); abort(); } } while (0)
;
281 }
282 bit_buf = value >> bit_left;
283 bit_left += BUF_BITS64;
284 }
285 bit_left -= n;
286
287 s->bit_buf = bit_buf;
288 s->bit_left = bit_left;
289}
290
291static inline void put_sbits(PutBitContext *pb, int n, int32_t value)
292{
293 av_assert2(n >= 0 && n <= 31)do { if (!(n >= 0 && n <= 31)) { av_log(((void*
)0), 0, "Assertion %s failed at %s:%d\n", "n >= 0 && n <= 31"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 293
); abort(); } } while (0)
;
294
295 put_bits(pb, n, av_zero_extendav_zero_extend_c(value, n));
296}
297
298/**
299 * Write exactly 32 bits into a bitstream.
300 */
301av_unused__attribute__((unused)) static void put_bits32(PutBitContext *s, uint32_t value)
302{
303 BitBuf bit_buf;
304 int bit_left;
305
306 if (BUF_BITS64 > 32) {
307 put_bits_no_assert(s, 32, value);
308 return;
309 }
310
311 bit_buf = s->bit_buf;
312 bit_left = s->bit_left;
313
314#ifdef BITSTREAM_WRITER_LE
315 bit_buf |= (BitBuf)value << (BUF_BITS64 - bit_left);
316 if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
317 AV_WLBUF(s->buf_ptr, bit_buf);
318 s->buf_ptr += sizeof(BitBuf);
319 } else {
320 av_log(NULL((void*)0), AV_LOG_ERROR16, "Internal error, put_bits buffer too small\n");
321 av_assert2(0)do { if (!(0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "0", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 321); abort(); } } while (0)
;
322 }
323 bit_buf = (uint64_t)value >> bit_left;
324#else
325 bit_buf = (uint64_t)bit_buf << bit_left;
326 bit_buf |= (BitBuf)value >> (BUF_BITS64 - bit_left);
327 if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
328 AV_WBBUF(s->buf_ptr, bit_buf);
329 s->buf_ptr += sizeof(BitBuf);
330 } else {
331 av_log(NULL((void*)0), AV_LOG_ERROR16, "Internal error, put_bits buffer too small\n");
332 av_assert2(0)do { if (!(0)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "0", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 332); abort(); } } while (0)
;
333 }
334 bit_buf = value;
335#endif
336
337 s->bit_buf = bit_buf;
338 s->bit_left = bit_left;
339}
340
341/**
342 * Write up to 63 bits into a bitstream.
343 */
344static inline void put_bits63(PutBitContext *s, int n, uint64_t value)
345{
346 av_assert2(n < 64U && value < (UINT64_C(1) << n))do { if (!(n < 64U && value < (1UL << n))
) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n", "n < 64U && value < (1UL << n)"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 346
); abort(); } } while (0)
;
347
348#if BUF_BITS64 >= 64
349 put_bits_no_assert(s, n, value);
350#else
351 if (n < 32)
352 put_bits(s, n, value);
353 else if (n == 32)
354 put_bits32(s, value);
355 else if (n < 64) {
356 uint32_t lo = value & 0xffffffff;
357 uint32_t hi = value >> 32;
358#ifdef BITSTREAM_WRITER_LE
359 put_bits32(s, lo);
360 put_bits(s, n - 32, hi);
361#else
362 put_bits(s, n - 32, hi);
363 put_bits32(s, lo);
364#endif
365 }
366#endif
367}
368
369/**
370 * Write up to 64 bits into a bitstream.
371 */
372static inline void put_bits64(PutBitContext *s, int n, uint64_t value)
373{
374 av_assert2((n == 64) || (n < 64 && value < (UINT64_C(1) << n)))do { if (!((n == 64) || (n < 64 && value < (1UL
<< n)))) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "(n == 64) || (n < 64 && value < (1UL << n))"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 374
); abort(); } } while (0)
;
375
376 if (n < 64) {
377 put_bits63(s, n, value);
378 } else {
379 uint32_t lo = value & 0xffffffff;
380 uint32_t hi = value >> 32;
381#ifdef BITSTREAM_WRITER_LE
382 put_bits32(s, lo);
383 put_bits32(s, hi);
384#else
385 put_bits32(s, hi);
386 put_bits32(s, lo);
387#endif
388 }
389}
390
391static inline void put_sbits63(PutBitContext *pb, int n, int64_t value)
392{
393 av_assert2(n >= 0 && n < 64)do { if (!(n >= 0 && n < 64)) { av_log(((void*)
0), 0, "Assertion %s failed at %s:%d\n", "n >= 0 && n < 64"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 393
); abort(); } } while (0)
;
394
395 put_bits63(pb, n, (uint64_t)(value) & (~(UINT64_MAX(18446744073709551615UL) << n)));
396}
397
398/**
399 * Return the pointer to the byte where the bitstream writer will put
400 * the next bit.
401 */
402static inline uint8_t *put_bits_ptr(PutBitContext *s)
403{
404 return s->buf_ptr;
405}
406
407/**
408 * Skip the given number of bytes.
409 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
410 */
411static inline void skip_put_bytes(PutBitContext *s, int n)
412{
413 av_assert2((put_bits_count(s) & 7) == 0)do { if (!((put_bits_count(s) & 7) == 0)) { av_log(((void
*)0), 0, "Assertion %s failed at %s:%d\n", "(put_bits_count(s) & 7) == 0"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 413
); abort(); } } while (0)
;
414 av_assert2(s->bit_left == BUF_BITS)do { if (!(s->bit_left == 64)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "s->bit_left == 64", "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h"
, 414); abort(); } } while (0)
;
415 av_assert0(n <= s->buf_end - s->buf_ptr)do { if (!(n <= s->buf_end - s->buf_ptr)) { av_log((
(void*)0), 0, "Assertion %s failed at %s:%d\n", "n <= s->buf_end - s->buf_ptr"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 415
); abort(); } } while (0)
;
416 s->buf_ptr += n;
417}
418
419/**
420 * Skip the given number of bits.
421 * Must only be used if the actual values in the bitstream do not matter.
422 * If n is < 0 the behavior is undefined.
423 */
424static inline void skip_put_bits(PutBitContext *s, int n)
425{
426 unsigned bits = BUF_BITS64 - s->bit_left + n;
427 s->buf_ptr += sizeof(BitBuf) * (bits / BUF_BITS64);
428 s->bit_left = BUF_BITS64 - (bits & (BUF_BITS64 - 1));
429}
430
431/**
432 * Change the end of the buffer.
433 *
434 * @param size the new size in bytes of the buffer where to put bits
435 */
436static inline void set_put_bits_buffer_size(PutBitContext *s, int size)
437{
438 av_assert0(size <= INT_MAX/8 - BUF_BITS)do { if (!(size <= 2147483647/8 - 64)) { av_log(((void*)0)
, 0, "Assertion %s failed at %s:%d\n", "size <= 2147483647/8 - 64"
, "/root/firefox-clang/media/ffvpx/libavcodec/put_bits.h", 438
); abort(); } } while (0)
;
439 s->buf_end = s->buf + size;
440}
441
442/**
443 * Pad the bitstream with zeros up to the next byte boundary.
444 */
445static inline void align_put_bits(PutBitContext *s)
446{
447 put_bits(s, s->bit_left & 7, 0);
27
Passing the value 0 via 3rd parameter 'value'
28
Calling 'put_bits'
448}
449
450#undef AV_WBBUF
451#undef AV_WLBUF
452
453#endif /* AVCODEC_PUT_BITS_H */