Unified · Split
| @@ -6,6 +6,7 @@ · 5 unmodified lines | ||
| 6 | 6 | ** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | +#include <assert.h> | |
| 9 | 10 | #include <stdio.h> |
| 10 | 11 | #include <stdlib.h> |
| 11 | 12 | #include <string.h> |
| @@ -299,9 +300,10 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star · 287 unmodified lines | ||
| 299 | 300 | { if (data_index >= 0) /* Avoid underflow access to filter->buffer. */ |
| 300 | 301 | { fraction = fp_to_double (filter_index) ; |
| 301 | 302 | indx = fp_to_int (filter_index) ; |
| 302 | − | |
| 303 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 303 | 304 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 304 | − | |
| 305 | + assert (data_index >= 0 && data_index < filter->b_len) ; | |
| 306 | + assert (data_index < filter->b_end) ; | |
| 305 | 307 | left += icoeff * filter->buffer [data_index] ; |
| 306 | 308 | } ; |
| 307 | 309 | |
| @@ -320,9 +322,10 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star · 12 unmodified lines | ||
| 320 | 322 | do |
| 321 | 323 | { fraction = fp_to_double (filter_index) ; |
| 322 | 324 | indx = fp_to_int (filter_index) ; |
| 323 | − | |
| 325 | + assert (indx < filter->coeff_half_len + 2) ; | |
| 324 | 326 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 325 | − | |
| 327 | + assert (data_index >= 0 && data_index < filter->b_len) ; | |
| 328 | + assert (data_index < filter->b_end) ; | |
| 326 | 329 | right += icoeff * filter->buffer [data_index] ; |
| 327 | 330 | |
| 328 | 331 | filter_index -= increment ; |
| @@ -446,9 +449,10 @@ calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t star · 117 unmodified lines | ||
| 446 | 449 | { if (data_index >= 0) /* Avoid underflow access to filter->buffer. */ |
| 447 | 450 | { fraction = fp_to_double (filter_index) ; |
| 448 | 451 | indx = fp_to_int (filter_index) ; |
| 449 | − | |
| 452 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 450 | 453 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 451 | − | |
| 454 | + assert (data_index >= 0 && data_index + 1 < filter->b_len) ; | |
| 455 | + assert (data_index + 1 < filter->b_end) ; | |
| 452 | 456 | left [0] += icoeff * filter->buffer [data_index] ; |
| 453 | 457 | left [1] += icoeff * filter->buffer [data_index + 1] ; |
| 454 | 458 | } ; |
| @@ -468,9 +472,10 @@ calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t star · 13 unmodified lines | ||
| 468 | 472 | do |
| 469 | 473 | { fraction = fp_to_double (filter_index) ; |
| 470 | 474 | indx = fp_to_int (filter_index) ; |
| 471 | − | |
| 475 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 472 | 476 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 473 | − | |
| 477 | + assert (data_index >= 0 && data_index + 1 < filter->b_len) ; | |
| 478 | + assert (data_index + 1 < filter->b_end) ; | |
| 474 | 479 | right [0] += icoeff * filter->buffer [data_index] ; |
| 475 | 480 | right [1] += icoeff * filter->buffer [data_index + 1] ; |
| 476 | 481 | |
| @@ -595,9 +600,10 @@ calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_ · 118 unmodified lines | ||
| 595 | 600 | { if (data_index >= 0) /* Avoid underflow access to filter->buffer. */ |
| 596 | 601 | { fraction = fp_to_double (filter_index) ; |
| 597 | 602 | indx = fp_to_int (filter_index) ; |
| 598 | − | |
| 603 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 599 | 604 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 600 | − | |
| 605 | + assert (data_index >= 0 && data_index + 3 < filter->b_len) ; | |
| 606 | + assert (data_index + 3 < filter->b_end) ; | |
| 601 | 607 | left [0] += icoeff * filter->buffer [data_index] ; |
| 602 | 608 | left [1] += icoeff * filter->buffer [data_index + 1] ; |
| 603 | 609 | left [2] += icoeff * filter->buffer [data_index + 2] ; |
| @@ -619,9 +625,10 @@ calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_ · 15 unmodified lines | ||
| 619 | 625 | do |
| 620 | 626 | { fraction = fp_to_double (filter_index) ; |
| 621 | 627 | indx = fp_to_int (filter_index) ; |
| 622 | − | |
| 628 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 623 | 629 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 624 | − | |
| 630 | + assert (data_index >= 0 && data_index + 3 < filter->b_len) ; | |
| 631 | + assert (data_index + 3 < filter->b_end) ; | |
| 625 | 632 | right [0] += icoeff * filter->buffer [data_index] ; |
| 626 | 633 | right [1] += icoeff * filter->buffer [data_index + 1] ; |
| 627 | 634 | right [2] += icoeff * filter->buffer [data_index + 2] ; |
| @@ -750,9 +757,10 @@ calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_f · 122 unmodified lines | ||
| 750 | 757 | { if (data_index >= 0) /* Avoid underflow access to filter->buffer. */ |
| 751 | 758 | { fraction = fp_to_double (filter_index) ; |
| 752 | 759 | indx = fp_to_int (filter_index) ; |
| 753 | − | |
| 760 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 754 | 761 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 755 | − | |
| 762 | + assert (data_index >= 0 && data_index + 5 < filter->b_len) ; | |
| 763 | + assert (data_index + 5 < filter->b_end) ; | |
| 756 | 764 | left [0] += icoeff * filter->buffer [data_index] ; |
| 757 | 765 | left [1] += icoeff * filter->buffer [data_index + 1] ; |
| 758 | 766 | left [2] += icoeff * filter->buffer [data_index + 2] ; |
| @@ -776,9 +784,10 @@ calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_f · 17 unmodified lines | ||
| 776 | 784 | do |
| 777 | 785 | { fraction = fp_to_double (filter_index) ; |
| 778 | 786 | indx = fp_to_int (filter_index) ; |
| 779 | − | |
| 787 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 780 | 788 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 781 | − | |
| 789 | + assert (data_index >= 0 && data_index + 5 < filter->b_len) ; | |
| 790 | + assert (data_index + 5 < filter->b_end) ; | |
| 782 | 791 | right [0] += icoeff * filter->buffer [data_index] ; |
| 783 | 792 | right [1] += icoeff * filter->buffer [data_index + 1] ; |
| 784 | 793 | right [2] += icoeff * filter->buffer [data_index + 2] ; |
| @@ -916,7 +925,7 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start · 131 unmodified lines | ||
| 916 | 925 | do |
| 917 | 926 | { fraction = fp_to_double (filter_index) ; |
| 918 | 927 | indx = fp_to_int (filter_index) ; |
| 919 | − | |
| 928 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 920 | 929 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 921 | 930 | |
| 922 | 931 | if (data_index >= 0) /* Avoid underflow access to filter->buffer. */ |
| @@ -924,6 +933,8 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start · 1 unmodified line | ||
| 924 | 933 | ** Duff's Device. |
| 925 | 934 | ** See : http://en.wikipedia.org/wiki/Duff's_device |
| 926 | 935 | */ |
| 936 | + assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ; | |
| 937 | + assert (data_index + channels - 1 < filter->b_end) ; | |
| 927 | 938 | ch = channels ; |
| 928 | 939 | do |
| 929 | 940 | { switch (ch % 8) |
| @@ -978,9 +989,10 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start · 48 unmodified lines | ||
| 978 | 989 | do |
| 979 | 990 | { fraction = fp_to_double (filter_index) ; |
| 980 | 991 | indx = fp_to_int (filter_index) ; |
| 981 | − | |
| 992 | + assert (indx >= 0 && indx + 1 < filter->coeff_half_len + 2) ; | |
| 982 | 993 | icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ; |
| 983 | − | |
| 994 | + assert (data_index >= 0 && data_index + channels - 1 < filter->b_len) ; | |
| 995 | + assert (data_index + channels - 1 < filter->b_end) ; | |
| 984 | 996 | ch = channels ; |
| 985 | 997 | do |
| 986 | 998 | { |