Bug Summary

File:libs/opus-1.1-p2/src/repacketizer_demo.c
Location:line 194, column 19
Description:Function call argument is an uninitialized value

Annotated Source Code

1/* Copyright (c) 2011 Xiph.Org Foundation
2 Written by Jean-Marc Valin */
3/*
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifdef HAVE_CONFIG_H1
29#include "config.h"
30#endif
31
32#include "opus.h"
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36
37#define MAX_PACKETOUT32000 32000
38
39void usage(char *argv0)
40{
41 fprintf(stderrstderr, "usage: %s [options] input_file output_file\n", argv0);
42}
43
44static void int_to_char(opus_uint32 i, unsigned char ch[4])
45{
46 ch[0] = i>>24;
47 ch[1] = (i>>16)&0xFF;
48 ch[2] = (i>>8)&0xFF;
49 ch[3] = i&0xFF;
50}
51
52static opus_uint32 char_to_int(unsigned char ch[4])
53{
54 return ((opus_uint32)ch[0]<<24) | ((opus_uint32)ch[1]<<16)
55 | ((opus_uint32)ch[2]<< 8) | (opus_uint32)ch[3];
56}
57
58int main(int argc, char *argv[])
59{
60 int i, eof=0;
61 FILE *fin, *fout;
62 unsigned char packets[48][1500];
63 int len[48];
64 int rng[48];
65 OpusRepacketizer *rp;
66 unsigned char output_packet[MAX_PACKETOUT32000];
67 int merge = 1, split=0;
68
69 if (argc < 3)
1
Assuming 'argc' is >= 3
2
Taking false branch
70 {
71 usage(argv[0]);
72 return EXIT_FAILURE1;
73 }
74 for (i=1;i<argc-2;i++)
3
Loop condition is true. Entering loop body
6
Loop condition is false. Execution continues on line 99
75 {
76 if (strcmp(argv[i], "-merge")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(argv[i]) && __builtin_constant_p ("-merge") &&
(__s1_len = __builtin_strlen (argv[i]), __s2_len = __builtin_strlen
("-merge"), (!((size_t)(const void *)((argv[i]) + 1) - (size_t
)(const void *)(argv[i]) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)(("-merge") + 1) - (size_t)(const void
*)("-merge") == 1) || __s2_len >= 4)) ? __builtin_strcmp (
argv[i], "-merge") : (__builtin_constant_p (argv[i]) &&
((size_t)(const void *)((argv[i]) + 1) - (size_t)(const void
*)(argv[i]) == 1) && (__s1_len = __builtin_strlen (argv
[i]), __s1_len < 4) ? (__builtin_constant_p ("-merge") &&
((size_t)(const void *)(("-merge") + 1) - (size_t)(const void
*)("-merge") == 1) ? __builtin_strcmp (argv[i], "-merge") : (
__extension__ ({ const unsigned char *__s2 = (const unsigned char
*) (const char *) ("-merge"); int __result = (((const unsigned
char *) (const char *) (argv[i]))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (argv[i]))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (argv[i]))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (argv[i]))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p ("-merge") && ((size_t
)(const void *)(("-merge") + 1) - (size_t)(const void *)("-merge"
) == 1) && (__s2_len = __builtin_strlen ("-merge"), __s2_len
< 4) ? (__builtin_constant_p (argv[i]) && ((size_t
)(const void *)((argv[i]) + 1) - (size_t)(const void *)(argv[
i]) == 1) ? __builtin_strcmp (argv[i], "-merge") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (argv[i]); int __result = (((const unsigned char *) (
const char *) ("-merge"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("-merge"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("-merge"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("-merge"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(argv[i], "-merge")))); })
==0)
4
Taking false branch
77 {
78 merge = atoi(argv[i+1]);
79 if(merge<1)
80 {
81 fprintf(stderrstderr, "-merge parameter must be at least 1.\n");
82 return EXIT_FAILURE1;
83 }
84 if(merge>48)
85 {
86 fprintf(stderrstderr, "-merge parameter must be less than 48.\n");
87 return EXIT_FAILURE1;
88 }
89 i++;
90 } else if (strcmp(argv[i], "-split")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(argv[i]) && __builtin_constant_p ("-split") &&
(__s1_len = __builtin_strlen (argv[i]), __s2_len = __builtin_strlen
("-split"), (!((size_t)(const void *)((argv[i]) + 1) - (size_t
)(const void *)(argv[i]) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)(("-split") + 1) - (size_t)(const void
*)("-split") == 1) || __s2_len >= 4)) ? __builtin_strcmp (
argv[i], "-split") : (__builtin_constant_p (argv[i]) &&
((size_t)(const void *)((argv[i]) + 1) - (size_t)(const void
*)(argv[i]) == 1) && (__s1_len = __builtin_strlen (argv
[i]), __s1_len < 4) ? (__builtin_constant_p ("-split") &&
((size_t)(const void *)(("-split") + 1) - (size_t)(const void
*)("-split") == 1) ? __builtin_strcmp (argv[i], "-split") : (
__extension__ ({ const unsigned char *__s2 = (const unsigned char
*) (const char *) ("-split"); int __result = (((const unsigned
char *) (const char *) (argv[i]))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (argv[i]))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (argv[i]))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (argv[i]))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p ("-split") && ((size_t
)(const void *)(("-split") + 1) - (size_t)(const void *)("-split"
) == 1) && (__s2_len = __builtin_strlen ("-split"), __s2_len
< 4) ? (__builtin_constant_p (argv[i]) && ((size_t
)(const void *)((argv[i]) + 1) - (size_t)(const void *)(argv[
i]) == 1) ? __builtin_strcmp (argv[i], "-split") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (argv[i]); int __result = (((const unsigned char *) (
const char *) ("-split"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("-split"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("-split"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("-split"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(argv[i], "-split")))); })
==0)
5
Taking true branch
91 split = 1;
92 else
93 {
94 fprintf(stderrstderr, "Unknown option: %s\n", argv[i]);
95 usage(argv[0]);
96 return EXIT_FAILURE1;
97 }
98 }
99 fin = fopen(argv[argc-2], "r");
100 if(fin==NULL((void*)0))
7
Assuming 'fin' is not equal to null
8
Taking false branch
101 {
102 fprintf(stderrstderr, "Error opening input file: %s\n", argv[argc-2]);
103 return EXIT_FAILURE1;
104 }
105 fout = fopen(argv[argc-1], "w");
106 if(fout==NULL((void*)0))
9
Assuming 'fout' is not equal to null
10
Taking false branch
107 {
108 fprintf(stderrstderr, "Error opening output file: %s\n", argv[argc-1]);
109 fclose(fin);
110 return EXIT_FAILURE1;
111 }
112
113 rp = opus_repacketizer_create();
114 while (!eof)
11
Loop condition is true. Entering loop body
115 {
116 int err;
117 int nb_packets=merge;
118 opus_repacketizer_init(rp);
119 for (i=0;i<nb_packets;i++)
12
Loop condition is true. Entering loop body
120 {
121 unsigned char ch[4];
122 err = fread(ch, 1, 4, fin);
123 len[i] = char_to_int(ch);
124 /*fprintf(stderr, "in len = %d\n", len[i]);*/
125 if (len[i]>1500 || len[i]<0)
13
Taking false branch
126 {
127 if (feof(fin))
128 {
129 eof = 1;
130 } else {
131 fprintf(stderrstderr, "Invalid payload length\n");
132 fclose(fin);
133 fclose(fout);
134 return EXIT_FAILURE1;
135 }
136 break;
137 }
138 err = fread(ch, 1, 4, fin);
139 rng[i] = char_to_int(ch);
140 err = fread(packets[i], 1, len[i], fin);
141 if (feof(fin))
14
Taking false branch
142 {
143 eof = 1;
144 break;
145 }
146 err = opus_repacketizer_cat(rp, packets[i], len[i]);
147 if (err!=OPUS_OK0)
15
Assuming 'err' is not equal to 0
16
Taking true branch
148 {
149 fprintf(stderrstderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
150 break;
17
Execution continues on line 153
151 }
152 }
153 nb_packets = i;
154
155 if (eof)
18
Taking false branch
156 break;
157
158 if (!split)
19
Taking false branch
159 {
160 err = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT32000);
161 if (err>0) {
162 unsigned char int_field[4];
163 int_to_char(err, int_field);
164 if(fwrite(int_field, 1, 4, fout)!=4){
165 fprintf(stderrstderr, "Error writing.\n");
166 return EXIT_FAILURE1;
167 }
168 int_to_char(rng[nb_packets-1], int_field);
169 if (fwrite(int_field, 1, 4, fout)!=4) {
170 fprintf(stderrstderr, "Error writing.\n");
171 return EXIT_FAILURE1;
172 }
173 if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
174 fprintf(stderrstderr, "Error writing.\n");
175 return EXIT_FAILURE1;
176 }
177 /*fprintf(stderr, "out len = %d\n", err);*/
178 } else {
179 fprintf(stderrstderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
180 }
181 } else {
182 int nb_frames = opus_repacketizer_get_nb_frames(rp);
183 for (i=0;i<nb_frames;i++)
20
Assuming 'i' is < 'nb_frames'
21
Loop condition is true. Entering loop body
184 {
185 err = opus_repacketizer_out_range(rp, i, i+1, output_packet, MAX_PACKETOUT32000);
186 if (err>0) {
22
Assuming 'err' is > 0
23
Taking true branch
187 unsigned char int_field[4];
188 int_to_char(err, int_field);
189 if (fwrite(int_field, 1, 4, fout)!=4) {
24
Taking false branch
190 fprintf(stderrstderr, "Error writing.\n");
191 return EXIT_FAILURE1;
192 }
193 if (i==nb_frames-1)
25
Taking true branch
194 int_to_char(rng[nb_packets-1], int_field);
26
Function call argument is an uninitialized value
195 else
196 int_to_char(0, int_field);
197 if (fwrite(int_field, 1, 4, fout)!=4) {
198 fprintf(stderrstderr, "Error writing.\n");
199 return EXIT_FAILURE1;
200 }
201 if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
202 fprintf(stderrstderr, "Error writing.\n");
203 return EXIT_FAILURE1;
204 }
205 /*fprintf(stderr, "out len = %d\n", err);*/
206 } else {
207 fprintf(stderrstderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
208 }
209
210 }
211 }
212 }
213
214 fclose(fin);
215 fclose(fout);
216 return EXIT_SUCCESS0;
217}