aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2025-04-20 21:29:47 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2025-04-25 23:01:38 +0200
commitc33f16db1b0e5fc0c5eede34922b8f19e43ce854 (patch)
treeae9f1ea77f0be47c161fb8b7d8a455eec08915e2
parente0a05456cd62e4127aaf2117833e371d103d5f4c (diff)
downloadffmpeg-c33f16db1b0e5fc0c5eede34922b8f19e43ce854.tar.gz
avcodec/webp: Avoid loop
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/webp.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index e26bf01c6a..7d77d64524 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -267,31 +267,24 @@ static int huff_reader_build_canonical(HuffReader *r, const uint8_t *code_length
len_counts[len] = nb_codes;
nb_codes += cnt;
}
+
+ for (int sym = 0; sym < alphabet_size; ++sym) {
+ if (code_lengths[sym]) {
+ unsigned idx = len_counts[code_lengths[sym]]++;
+ syms[idx] = sym;
+ lens[idx] = code_lengths[sym];
+ }
+ }
if (nb_codes <= 1) {
if (nb_codes == 1) {
/* special-case 1 symbol since the vlc reader cannot handle it */
r->nb_symbols = 1;
r->simple = 1;
- for (int sym = 0;; ++sym) {
- av_assert1(sym < alphabet_size);
- if (code_lengths[sym]) {
- r->simple_symbols[0] = sym;
- return 0;
- }
- }
+ r->simple_symbols[0] = syms[0];
}
// No symbols
return AVERROR_INVALIDDATA;
}
-
- for (int sym = 0; sym < alphabet_size; ++sym) {
- if (code_lengths[sym]) {
- unsigned idx = len_counts[code_lengths[sym]]++;
- syms[idx] = sym;
- lens[idx] = code_lengths[sym];
- }
- }
-
ret = ff_vlc_init_from_lengths(&r->vlc, 8, nb_codes, lens, 1,
syms, 2, 2, 0, VLC_INIT_OUTPUT_LE, logctx);
if (ret < 0)