external/alsa-utils
Revisión | 819e04c7a1958a1c4378d914b38bddaf248d9fc0 (tree) |
---|---|
Tiempo | 2019-03-13 22:42:42 |
Autor | Jaroslav Kysela <perex@pere...> |
Commiter | Jaroslav Kysela |
axfer: coverity fixes
- container-voc.c - out of array access
- container-voc.c - handle correctly eof
- frame_cache.c - correct memory allocation
- container.c - byte_count might be used uninitialized
- xfer-libasound-irq-mmap.c - fix avail signess
- xfer-options.c - fix potential 32-bit wrap for duration
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
@@ -234,7 +234,7 @@ static int build_time_constant(unsigned int frames_per_second, | ||
234 | 234 | frames_per_second) |
235 | 235 | break; |
236 | 236 | } |
237 | - if (i < ARRAY_SIZE(ex_v110_time_consts) || | |
237 | + if (i < ARRAY_SIZE(ex_v110_time_consts) && | |
238 | 238 | frames_per_second <= 192000) { |
239 | 239 | *code = ex_v110_time_consts[i].code; |
240 | 240 | } else { |
@@ -520,29 +520,31 @@ static int detect_format_block(struct container_context *cntr) | ||
520 | 520 | { |
521 | 521 | struct parser_state *state = cntr->private_data; |
522 | 522 | struct block_header header; |
523 | - void *buf = NULL; | |
523 | + void *buf; | |
524 | 524 | int err; |
525 | 525 | |
526 | 526 | again: |
527 | + buf = NULL; | |
527 | 528 | err = cache_data_block(cntr, &header, &buf); |
528 | 529 | if (err < 0) |
529 | 530 | return err; |
531 | + if (buf) { | |
532 | + if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT) { | |
533 | + err = parse_extended_v110_format(state, buf); | |
534 | + } else if (header.type == BLOCK_TYPE_V120_DATA) { | |
535 | + err = parse_v120_format_block(state, buf); | |
536 | + } else if (header.type == BLOCK_TYPE_V110_DATA) { | |
537 | + err = parse_v110_data(state, buf); | |
538 | + } else { | |
539 | + free(buf); | |
540 | + goto again; | |
541 | + } | |
530 | 542 | |
531 | - if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT) { | |
532 | - err = parse_extended_v110_format(state, buf); | |
533 | - } else if (header.type == BLOCK_TYPE_V120_DATA) { | |
534 | - err = parse_v120_format_block(state, buf); | |
535 | - } else if (header.type == BLOCK_TYPE_V110_DATA) { | |
536 | - err = parse_v110_data(state, buf); | |
537 | - } else { | |
538 | 543 | free(buf); |
539 | - goto again; | |
540 | - } | |
541 | - | |
542 | - free(buf); | |
543 | 544 | |
544 | - if (err < 0) | |
545 | - return err; | |
545 | + if (err < 0) | |
546 | + return err; | |
547 | + } | |
546 | 548 | |
547 | 549 | // Expect to detect block_v110_data. |
548 | 550 | if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT) |
@@ -296,7 +296,7 @@ int container_context_pre_process(struct container_context *cntr, | ||
296 | 296 | unsigned int *frames_per_second, |
297 | 297 | uint64_t *frame_count) |
298 | 298 | { |
299 | - uint64_t byte_count; | |
299 | + uint64_t byte_count = 0; | |
300 | 300 | unsigned int bytes_per_frame; |
301 | 301 | int err; |
302 | 302 |
@@ -50,13 +50,18 @@ int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access, | ||
50 | 50 | unsigned int samples_per_frame, |
51 | 51 | unsigned int frames_per_cache) |
52 | 52 | { |
53 | + cache->access = access; | |
54 | + cache->remained_count = 0; | |
55 | + cache->bytes_per_sample = bytes_per_sample; | |
56 | + cache->samples_per_frame = samples_per_frame; | |
57 | + cache->frames_per_cache = frames_per_cache; | |
58 | + | |
53 | 59 | if (access == SND_PCM_ACCESS_RW_INTERLEAVED) |
54 | 60 | cache->align_frames = align_frames_in_i; |
55 | 61 | else if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED) |
56 | 62 | cache->align_frames = align_frames_in_n; |
57 | 63 | else |
58 | 64 | return -EINVAL; |
59 | - cache->access = access; | |
60 | 65 | |
61 | 66 | if (access == SND_PCM_ACCESS_RW_INTERLEAVED) { |
62 | 67 | char *buf; |
@@ -64,45 +69,42 @@ int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access, | ||
64 | 69 | buf = calloc(frames_per_cache, |
65 | 70 | bytes_per_sample * samples_per_frame); |
66 | 71 | if (buf == NULL) |
67 | - return -ENOMEM; | |
72 | + goto nomem; | |
68 | 73 | cache->buf = buf; |
69 | 74 | cache->buf_ptr = buf; |
70 | 75 | } else { |
71 | - char **bufs; | |
72 | - char **buf_ptrs; | |
76 | + char **bufs = calloc(samples_per_frame, sizeof(*bufs)); | |
77 | + char **buf_ptrs = calloc(samples_per_frame, sizeof(*buf_ptrs)); | |
73 | 78 | int i; |
74 | 79 | |
75 | - bufs = calloc(samples_per_frame, sizeof(*bufs)); | |
76 | - if (bufs == NULL) | |
77 | - return -ENOMEM; | |
78 | - buf_ptrs = calloc(samples_per_frame, sizeof(*buf_ptrs)); | |
79 | - if (buf_ptrs == NULL) | |
80 | - return -ENOMEM; | |
80 | + cache->buf = bufs; | |
81 | + cache->buf_ptr = buf_ptrs; | |
82 | + if (bufs == NULL || buf_ptrs == NULL) | |
83 | + goto nomem; | |
81 | 84 | for (i = 0; i < samples_per_frame; ++i) { |
82 | 85 | bufs[i] = calloc(frames_per_cache, bytes_per_sample); |
83 | 86 | if (bufs[i] == NULL) |
84 | - return -ENOMEM; | |
87 | + goto nomem; | |
85 | 88 | buf_ptrs[i] = bufs[i]; |
86 | 89 | } |
87 | - cache->buf = bufs; | |
88 | - cache->buf_ptr = buf_ptrs; | |
89 | 90 | } |
90 | 91 | |
91 | - cache->remained_count = 0; | |
92 | - cache->bytes_per_sample = bytes_per_sample; | |
93 | - cache->samples_per_frame = samples_per_frame; | |
94 | - cache->frames_per_cache = frames_per_cache; | |
95 | 92 | |
96 | 93 | return 0; |
94 | + | |
95 | +nomem: | |
96 | + frame_cache_destroy(cache); | |
97 | + return -ENOMEM; | |
97 | 98 | } |
98 | 99 | |
99 | 100 | void frame_cache_destroy(struct frame_cache *cache) |
100 | 101 | { |
101 | 102 | if (cache->access == SND_PCM_ACCESS_RW_NONINTERLEAVED) { |
102 | - int i; | |
103 | - for (i = 0; i < cache->samples_per_frame; ++i) { | |
104 | - char **bufs = cache->buf; | |
105 | - free(bufs[i]); | |
103 | + char **bufs = cache->buf; | |
104 | + if (bufs) { | |
105 | + int i; | |
106 | + for (i = 0; i < cache->samples_per_frame; ++i) | |
107 | + free(bufs[i]); | |
106 | 108 | } |
107 | 109 | free(cache->buf_ptr); |
108 | 110 | } |
@@ -75,7 +75,7 @@ static int irq_mmap_process_frames(struct libasound_state *state, | ||
75 | 75 | struct map_layout *layout = state->private_data; |
76 | 76 | const snd_pcm_channel_area_t *areas; |
77 | 77 | snd_pcm_uframes_t frame_offset; |
78 | - snd_pcm_uframes_t avail; | |
78 | + snd_pcm_sframes_t avail; | |
79 | 79 | unsigned int avail_count; |
80 | 80 | void *frame_buf; |
81 | 81 | snd_pcm_sframes_t consumed_count; |
@@ -395,7 +395,7 @@ void xfer_options_calculate_duration(struct xfer_context *xfer, | ||
395 | 395 | uint64_t frame_count; |
396 | 396 | |
397 | 397 | if (xfer->duration_seconds > 0) { |
398 | - frame_count = xfer->duration_seconds * xfer->frames_per_second; | |
398 | + frame_count = (uint64_t)xfer->duration_seconds * (uint64_t)xfer->frames_per_second; | |
399 | 399 | if (frame_count < *total_frame_count) |
400 | 400 | *total_frame_count = frame_count; |
401 | 401 | } |