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
148148 int
149149 sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
150150 { SINC_FILTER *filter, temp_filter ;
151− int count ;
151+ int count, bits ;
152152
153153 /* Quick sanity check. */
154154 if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
@@ -217,9 +217,11 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 62 unmodified lines
217217
218218 sinc_reset (psrc) ;
219219
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) ;
221223
222− if (abs (count - filter->coeff_half_len) >= 1)
224+ if (bits + SHIFT_BITS - 1 >= (int) (sizeof (increment_t) * 8))
223225 return SRC_ERR_FILTER_LEN ;
224226
225227 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