Bug Summary

File:read-sound-file.c
Warning:line 194, column 17
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name read-sound-file.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -fapprox-func -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -D HAVE_CONFIG_H -I . -I .. -D KA_PLUGIN_PATH="/usr/local/lib/libkanberra-0.31" -D KA_MACHINE_ID="/usr/local/var/lib/dbus/machine-id" -D PIC -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-long-long -Wno-overlength-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -fconst-strings -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2022-12-24-113220-18448-1 -x c read-sound-file.c
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3/***
4 This file is part of libkanberra.
5
6 Copyright 2008 Lennart Poettering
7
8 libkanberra is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 2.1 of the
11 License, or (at your option) any later version.
12
13 libkanberra is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with libkanberra. If not, see
20 <http://www.gnu.org/licenses/>.
21***/
22
23#ifdef HAVE_CONFIG_H1
24#include <config.h>
25#endif
26
27#include <errno(*__errno_location ()).h>
28
29#include "read-sound-file.h"
30#include "read-wav.h"
31#include "read-vorbis.h"
32#include "macro.h"
33#include "malloc.h"
34#include "kanberra.h"
35
36struct ka_sound_file {
37 ka_wav *wav;
38 ka_vorbis *vorbis;
39 char *filename;
40
41 unsigned nchannels;
42 unsigned rate;
43 ka_sample_type_t type;
44};
45
46int ka_sound_file_open(ka_sound_file **_f, const char *fn) {
47 FILE *file;
48 ka_sound_file *f;
49 int ret;
50
51 ka_return_val_if_fail(_f, KA_ERROR_INVALID)do { if ((__builtin_expect((!(_f)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "_f"
, "read-sound-file.c", 51, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
52 ka_return_val_if_fail(fn, KA_ERROR_INVALID)do { if ((__builtin_expect((!(fn)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "fn"
, "read-sound-file.c", 52, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
53
54 if (!(f = ka_new0(ka_sound_file, 1)((ka_sound_file*) calloc(1, (sizeof(ka_sound_file)*(1))))))
55 return KA_ERROR_OOM;
56
57 if (!(f->filename = ka_strdupstrdup(fn))) {
58 ret = KA_ERROR_OOM;
59 goto fail;
60 }
61
62 if (!(file = fopen(fn, "r"))) {
63 ret = errno(*__errno_location ()) == ENOENT2 ? KA_ERROR_NOTFOUND : KA_ERROR_SYSTEM;
64 goto fail;
65 }
66
67 if ((ret = ka_wav_open(&f->wav, file)) == KA_SUCCESS) {
68 f->nchannels = ka_wav_get_nchannels(f->wav);
69 f->rate = ka_wav_get_rate(f->wav);
70 f->type = ka_wav_get_sample_type(f->wav);
71 *_f = f;
72 return KA_SUCCESS;
73 }
74
75 if (ret == KA_ERROR_CORRUPT) {
76
77 if (fseek(file, 0, SEEK_SET0) < 0) {
78 ret = KA_ERROR_SYSTEM;
79 goto fail;
80 }
81
82 if ((ret = ka_vorbis_open(&f->vorbis, file)) == KA_SUCCESS) {
83 f->nchannels = ka_vorbis_get_nchannels(f->vorbis);
84 f->rate = ka_vorbis_get_rate(f->vorbis);
85 f->type = KA_SAMPLE_S16NE;
86 *_f = f;
87 return KA_SUCCESS;
88 }
89 }
90
91fail:
92
93 ka_freefree(f->filename);
94 ka_freefree(f);
95
96 return ret;
97}
98
99void ka_sound_file_close(ka_sound_file *f) {
100 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 100, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
101
102 if (f->wav)
103 ka_wav_close(f->wav);
104 if (f->vorbis)
105 ka_vorbis_close(f->vorbis);
106
107 ka_freefree(f->filename);
108 ka_freefree(f);
109}
110
111unsigned ka_sound_file_get_nchannels(ka_sound_file *f) {
112 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 112, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
113 return f->nchannels;
114}
115
116unsigned ka_sound_file_get_rate(ka_sound_file *f) {
117 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 117, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
118 return f->rate;
119}
120
121ka_sample_type_t ka_sound_file_get_sample_type(ka_sound_file *f) {
122 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 122, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
123 return f->type;
124}
125
126const ka_channel_position_t* ka_sound_file_get_channel_map(ka_sound_file *f) {
127 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 127, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
128
129 if (f->wav)
130 return ka_wav_get_channel_map(f->wav);
131 else
132 return ka_vorbis_get_channel_map(f->vorbis);
133}
134
135int ka_sound_file_read_int16(ka_sound_file *f, int16_t *d, size_t *n) {
136 ka_return_val_if_fail(f, KA_ERROR_INVALID)do { if ((__builtin_expect((!(f)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "f"
, "read-sound-file.c", 136, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
137 ka_return_val_if_fail(d, KA_ERROR_INVALID)do { if ((__builtin_expect((!(d)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "d"
, "read-sound-file.c", 137, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
138 ka_return_val_if_fail(n, KA_ERROR_INVALID)do { if ((__builtin_expect((!(n)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "n"
, "read-sound-file.c", 138, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
139 ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID)do { if ((__builtin_expect((!(*n > 0)),0))) { if (ka_debug
()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "*n > 0" , "read-sound-file.c", 139, __PRETTY_FUNCTION__
); return (KA_ERROR_INVALID); } } while((0))
;
140 ka_return_val_if_fail(f->wav || f->vorbis, KA_ERROR_STATE)do { if ((__builtin_expect((!(f->wav || f->vorbis)),0))
) { if (ka_debug()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "f->wav || f->vorbis" , "read-sound-file.c", 140, __PRETTY_FUNCTION__
); return (KA_ERROR_STATE); } } while((0))
;
141 ka_return_val_if_fail(f->type == KA_SAMPLE_S16NE || f->type == KA_SAMPLE_S16RE, KA_ERROR_STATE)do { if ((__builtin_expect((!(f->type == KA_SAMPLE_S16NE ||
f->type == KA_SAMPLE_S16RE)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "f->type == KA_SAMPLE_S16NE || f->type == KA_SAMPLE_S16RE"
, "read-sound-file.c", 141, __PRETTY_FUNCTION__); return (KA_ERROR_STATE
); } } while((0))
;
142
143 if (f->wav)
144 return ka_wav_read_s16le(f->wav, d, n);
145 else
146 return ka_vorbis_read_s16ne(f->vorbis, d, n);
147}
148
149int ka_sound_file_read_uint8(ka_sound_file *f, uint8_t *d, size_t *n) {
150 ka_return_val_if_fail(f, KA_ERROR_INVALID)do { if ((__builtin_expect((!(f)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "f"
, "read-sound-file.c", 150, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
151 ka_return_val_if_fail(d, KA_ERROR_INVALID)do { if ((__builtin_expect((!(d)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "d"
, "read-sound-file.c", 151, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
152 ka_return_val_if_fail(n, KA_ERROR_INVALID)do { if ((__builtin_expect((!(n)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "n"
, "read-sound-file.c", 152, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
153 ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID)do { if ((__builtin_expect((!(*n > 0)),0))) { if (ka_debug
()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "*n > 0" , "read-sound-file.c", 153, __PRETTY_FUNCTION__
); return (KA_ERROR_INVALID); } } while((0))
;
154 ka_return_val_if_fail(f->wav && !f->vorbis, KA_ERROR_STATE)do { if ((__builtin_expect((!(f->wav && !f->vorbis
)),0))) { if (ka_debug()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "f->wav && !f->vorbis" , "read-sound-file.c",
154, __PRETTY_FUNCTION__); return (KA_ERROR_STATE); } } while
((0))
;
155 ka_return_val_if_fail(f->type == KA_SAMPLE_U8, KA_ERROR_STATE)do { if ((__builtin_expect((!(f->type == KA_SAMPLE_U8)),0)
)) { if (ka_debug()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "f->type == KA_SAMPLE_U8" , "read-sound-file.c", 155, __PRETTY_FUNCTION__
); return (KA_ERROR_STATE); } } while((0))
;
156
157 if (f->wav)
158 return ka_wav_read_u8(f->wav, d, n);
159
160 return KA_ERROR_STATE;
161}
162
163int ka_sound_file_read_arbitrary(ka_sound_file *f, void *d, size_t *n) {
164 int ret;
165
166 ka_return_val_if_fail(f, KA_ERROR_INVALID)do { if ((__builtin_expect((!(f)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "f"
, "read-sound-file.c", 166, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
167 ka_return_val_if_fail(d, KA_ERROR_INVALID)do { if ((__builtin_expect((!(d)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "d"
, "read-sound-file.c", 167, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
168 ka_return_val_if_fail(n, KA_ERROR_INVALID)do { if ((__builtin_expect((!(n)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "n"
, "read-sound-file.c", 168, __PRETTY_FUNCTION__); return (KA_ERROR_INVALID
); } } while((0))
;
169 ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID)do { if ((__builtin_expect((!(*n > 0)),0))) { if (ka_debug
()) fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s().\n"
, "*n > 0" , "read-sound-file.c", 169, __PRETTY_FUNCTION__
); return (KA_ERROR_INVALID); } } while((0))
;
170
171 switch (f->type) {
172 case KA_SAMPLE_S16NE:
173 case KA_SAMPLE_S16RE: {
174 size_t k;
175
176 k = *n / sizeof(int16_t);
177 if ((ret = ka_sound_file_read_int16(f, d, &k)) == KA_SUCCESS)
178 *n = k * sizeof(int16_t);
179
180 break;
181 }
182
183 case KA_SAMPLE_U8: {
184 size_t k;
185
186 k = *n;
187 if ((ret = ka_sound_file_read_uint8(f, d, &k)) == KA_SUCCESS)
188 *n = k;
189
190 break;
191 }
192
193 default:
194 ka_assert_not_reached()do { fprintf(stderr, "Code should not be reached at %s:%u, function %s(). Aborting.\n"
, "read-sound-file.c", 194, __PRETTY_FUNCTION__); abort(); } while
((0))
;
This statement is never executed
195 }
196
197 return ret;
198}
199
200off_t ka_sound_file_get_size(ka_sound_file *f) {
201 ka_return_val_if_fail(f, (off_t) -1)do { if ((__builtin_expect((!(f)),0))) { if (ka_debug()) fprintf
(stderr, "Assertion '%s' failed at %s:%u, function %s().\n", "f"
, "read-sound-file.c", 201, __PRETTY_FUNCTION__); return ((off_t
) -1); } } while((0))
;
202
203 if (f->wav)
204 return ka_wav_get_size(f->wav);
205 else
206 return ka_vorbis_get_size(f->vorbis);
207}
208
209size_t ka_sound_file_frame_size(ka_sound_file *f) {
210 unsigned c;
211
212 ka_assert(f)do { if ((__builtin_expect((!(f)),0))) { fprintf(stderr, "Assertion '%s' failed at %s:%u, function %s(). Aborting.\n"
, "f" , "read-sound-file.c", 212, __PRETTY_FUNCTION__); abort
(); } } while ((0))
;
213
214 c = ka_sound_file_get_nchannels(f);
215
216 return c * (ka_sound_file_get_sample_type(f) == KA_SAMPLE_U8 ? 1U : 2U);
217}