Bug Summary

File:root/firefox-clang/media/ffvpx/libavcodec/pthread.c
Warning:line 125, column 5
Undefined or garbage value returned to caller

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 pthread.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 -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -include libavutil_visibility.h -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 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -I /root/firefox-clang/modules/fdlibm/inexact-math-override -I /root/firefox-clang/third_party/khronos/vulkan-headers/include -I /root/firefox-clang/media/mozva -I /root/firefox-clang/media/libopus/include -I /root/firefox-clang/media/libvorbis -I /root/firefox-clang/media/libvpx -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/pthread.c
1/*
2 * Copyright (c) 2004 Roman Shaposhnik
3 * Copyright (c) 2008 Alexander Strange (astrange@ithinksw.com)
4 *
5 * Many thanks to Steven M. Schultz for providing clever ideas and
6 * to Michael Niedermayer <michaelni@gmx.at> for writing initial
7 * implementation.
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26/**
27 * @file
28 * Multithreading support functions
29 * @see doc/multithreading.txt
30 */
31
32#include "libavutil/attributes.h"
33#include "libavutil/thread.h"
34
35#include "avcodec.h"
36#include "avcodec_internal.h"
37#include "codec_internal.h"
38#include "pthread_internal.h"
39
40/**
41 * Set the threading algorithms used.
42 *
43 * Threading requires more than one thread.
44 * Frame threading requires entire frames to be passed to the codec,
45 * and introduces extra decoding delay, so is incompatible with low_delay.
46 *
47 * @param avctx The context.
48 */
49static av_cold__attribute__((cold)) void validate_thread_parameters(AVCodecContext *avctx)
50{
51 int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS(1 << 12))
52 && !(avctx->flags & AV_CODEC_FLAG_LOW_DELAY(1 << 19))
53 && !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS(1 << 15));
54 if (avctx->thread_count == 1) {
55 avctx->active_thread_type = 0;
56 } else if (frame_threading_supported && (avctx->thread_type & FF_THREAD_FRAME1)) {
57 avctx->active_thread_type = FF_THREAD_FRAME1;
58 } else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS(1 << 13) &&
59 avctx->thread_type & FF_THREAD_SLICE2) {
60 avctx->active_thread_type = FF_THREAD_SLICE2;
61 } else if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_AUTO_THREADS(1 << 7))) {
62 avctx->thread_count = 1;
63 avctx->active_thread_type = 0;
64 }
65
66 if (avctx->thread_count > MAX_AUTO_THREADS16)
67 av_log(avctx, AV_LOG_WARNING24,
68 "Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",
69 avctx->thread_count, MAX_AUTO_THREADS16);
70}
71
72av_cold__attribute__((cold)) int ff_thread_init(AVCodecContext *avctx)
73{
74 validate_thread_parameters(avctx);
75
76 if (avctx->active_thread_type&FF_THREAD_SLICE2)
77 return ff_slice_thread_init(avctx);
78 else if (avctx->active_thread_type&FF_THREAD_FRAME1)
79 return ff_frame_thread_init(avctx);
80
81 return 0;
82}
83
84av_cold__attribute__((cold)) void ff_thread_free(AVCodecContext *avctx)
85{
86 if (avctx->active_thread_type&FF_THREAD_FRAME1)
87 ff_frame_thread_free(avctx, avctx->thread_count);
88 else
89 ff_slice_thread_free(avctx);
90}
91
92av_cold__attribute__((cold)) void ff_pthread_free(void *obj, const unsigned offsets[])
93{
94 unsigned cnt = *(unsigned*)((char*)obj + offsets[0]);
95 const unsigned *cur_offset = offsets;
96
97 *(unsigned*)((char*)obj + offsets[0]) = 0;
98
99 for (; *(++cur_offset) != THREAD_SENTINEL0 && cnt; cnt--)
100 pthread_mutex_destroystrict_pthread_mutex_destroy((pthread_mutex_t*)((char*)obj + *cur_offset));
101 for (; *(++cur_offset) != THREAD_SENTINEL0 && cnt; cnt--)
102 pthread_cond_destroystrict_pthread_cond_destroy ((pthread_cond_t *)((char*)obj + *cur_offset));
103}
104
105av_cold__attribute__((cold)) int ff_pthread_init(void *obj, const unsigned offsets[])
106{
107 const unsigned *cur_offset = offsets;
108 unsigned cnt = 0;
109 int err;
1
'err' declared without an initial value
110
111#define PTHREAD_INIT_LOOP(type)for (; *(++cur_offset) != 0; cnt++) { pthread_type_t *dst = (
void*)((char*)obj + *cur_offset); err = pthread_type_init(dst
, ((void*)0)); if (err) { err = (-(err)); goto fail; } }
\
112 for (; *(++cur_offset) != THREAD_SENTINEL0; cnt++) { \
113 pthread_ ## type ## _t *dst = (void*)((char*)obj + *cur_offset); \
114 err = pthread_ ## type ## _init(dst, NULL((void*)0)); \
115 if (err) { \
116 err = AVERROR(err)(-(err)); \
117 goto fail; \
118 } \
119 }
120 PTHREAD_INIT_LOOP(mutex)for (; *(++cur_offset) != 0; cnt++) { pthread_mutex_t *dst = (
void*)((char*)obj + *cur_offset); err = strict_pthread_mutex_init
(dst, ((void*)0)); if (err) { err = (-(err)); goto fail; } }
2
Assuming the condition is false
3
Loop condition is false. Execution continues on line 121
121 PTHREAD_INIT_LOOP(cond)for (; *(++cur_offset) != 0; cnt++) { pthread_cond_t *dst = (
void*)((char*)obj + *cur_offset); err = strict_pthread_cond_init
(dst, ((void*)0)); if (err) { err = (-(err)); goto fail; } }
4
Assuming the condition is false
5
Loop condition is false. Execution continues on line 124
122
123fail:
124 *(unsigned*)((char*)obj + offsets[0]) = cnt;
125 return err;
6
Undefined or garbage value returned to caller
126}