Mercurial > libavcodec.hg
comparison vorbis.c @ 3084:d37c1e2f715d libavcodec
10l (malloc check with the wrong pointer)
Simplification: I have to reconsider this trees and forest thing...
Also readded and documented the check i had in the beginning and removed
before applying. It avoids a possible div by zero.
author | al |
---|---|
date | Sat, 04 Feb 2006 09:59:48 +0000 |
parents | 0995d7ddeb58 |
children | 03582724f3de |
comparison
equal
deleted
inserted
replaced
3083:0995d7ddeb58 | 3084:d37c1e2f715d |
---|---|
543 | 543 |
544 floor_setup->data.t0.order=get_bits(gb, 8); | 544 floor_setup->data.t0.order=get_bits(gb, 8); |
545 floor_setup->data.t0.rate=get_bits(gb, 16); | 545 floor_setup->data.t0.rate=get_bits(gb, 16); |
546 floor_setup->data.t0.bark_map_size=get_bits(gb, 16); | 546 floor_setup->data.t0.bark_map_size=get_bits(gb, 16); |
547 floor_setup->data.t0.amplitude_bits=get_bits(gb, 6); | 547 floor_setup->data.t0.amplitude_bits=get_bits(gb, 6); |
548 /* zero would result in a div by zero later * | |
549 * 2^0 - 1 == 0 */ | |
550 if (floor_setup->data.t0.amplitude_bits == 0) { | |
551 av_log(vc->avccontext, AV_LOG_ERROR, | |
552 "Floor 0 amplitude bits is 0.\n"); | |
553 return 1; | |
554 } | |
548 floor_setup->data.t0.amplitude_offset=get_bits(gb, 8); | 555 floor_setup->data.t0.amplitude_offset=get_bits(gb, 8); |
549 floor_setup->data.t0.num_books=get_bits(gb, 4)+1; | 556 floor_setup->data.t0.num_books=get_bits(gb, 4)+1; |
550 | 557 |
551 /* allocate mem for booklist */ | 558 /* allocate mem for booklist */ |
552 floor_setup->data.t0.book_list= | 559 floor_setup->data.t0.book_list= |
572 /* codebook dim is for padding if codebook dim doesn't * | 579 /* codebook dim is for padding if codebook dim doesn't * |
573 * divide order+1 then we need to read more data */ | 580 * divide order+1 then we need to read more data */ |
574 floor_setup->data.t0.lsp= | 581 floor_setup->data.t0.lsp= |
575 av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) | 582 av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) |
576 * sizeof(float)); | 583 * sizeof(float)); |
577 if(!floor_setup->data.t0.book_list) { return 1; } | 584 if(!floor_setup->data.t0.lsp) { return 1; } |
578 } | 585 } |
579 | 586 |
580 #ifdef V_DEBUG /* debug output parsed headers */ | 587 #ifdef V_DEBUG /* debug output parsed headers */ |
581 AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order); | 588 AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order); |
582 AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate); | 589 AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate); |
1065 q *= q; | 1072 q *= q; |
1066 } | 1073 } |
1067 | 1074 |
1068 /* calculate linear floor value */ | 1075 /* calculate linear floor value */ |
1069 { | 1076 { |
1070 int_fast32_t pow_of_two=2, exponent=vf->amplitude_bits; | |
1071 if ( vf->amplitude_bits ) { | |
1072 while ( --exponent ) { pow_of_two <<= 1; } | |
1073 } | |
1074 else { pow_of_two=1; } | |
1075 q=exp( ( | 1077 q=exp( ( |
1076 ( (amplitude*vf->amplitude_offset)/ | 1078 ( (amplitude*vf->amplitude_offset)/ |
1077 ((pow_of_two-1) * sqrt(p+q)) ) | 1079 (((1<<vf->amplitude_bits)-1) * sqrt(p+q)) ) |
1078 - vf->amplitude_offset ) * .11512925f | 1080 - vf->amplitude_offset ) * .11512925f |
1079 ); | 1081 ); |
1080 } | 1082 } |
1081 | 1083 |
1082 /* fill vector */ | 1084 /* fill vector */ |