[FFmpeg-cvslog] avcodec/webp: Avoid loop
Andreas Rheinhardt
git at videolan.org
Sat Apr 26 01:15:15 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 20 21:29:47 2025 +0200| [c33f16db1b0e5fc0c5eede34922b8f19e43ce854] | committer: Andreas Rheinhardt
avcodec/webp: Avoid loop
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c33f16db1b0e5fc0c5eede34922b8f19e43ce854
---
libavcodec/webp.c | 25 +++++++++----------------
1 file 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)
More information about the ffmpeg-cvslog
mailing list