History

Improve checking for possible overflow in fixed point counters.

Erik de Castro Lopo committed 22 years ago

Commit 2f7c74f1 parent 40148911 file · +5 −3Browse files

Unified · Split

src/src_sinc.c+5−3
@@ -148,7 +148,7 @@ sinc_get_description (int src_enum) · 147 unmodified lines
148int148int
149sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)149sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
150{ SINC_FILTER *filter, temp_filter ;150{ SINC_FILTER *filter, temp_filter ;
151 int count ;151 int count, bits ;
152 152
153 /* Quick sanity check. */153 /* Quick sanity check. */
154 if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)154 if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
@@ -217,9 +217,11 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 62 unmodified lines
217 217
218 sinc_reset (psrc) ;218 sinc_reset (psrc) ;
219 219
220 count = lrint ((filter->coeff_half_len * INT_TO_FP (1)) / FP_ONE) ;220 count = filter->coeff_half_len ;
221 for (bits = 0 ; (1 << bits) < count ; bits++)
222 count |= (1 << bits) ;
221 223
222 if (abs (count - filter->coeff_half_len) >= 1)224 if (bits + SHIFT_BITS - 1 >= (int) (sizeof (increment_t) * 8))
223 return SRC_ERR_FILTER_LEN ;225 return SRC_ERR_FILTER_LEN ;
224 226
225 return SRC_ERR_NO_ERROR ;227 return SRC_ERR_NO_ERROR ;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t