History

Reduce usage of flexible array fields

evpobr committed 6 years ago

Commit 36dfd681 parent 8a83ad33 files · +94 −32Browse files

Showing the changes to src/src_sinc.c (1 of 3 files). Show all

Unified · Split

src/src_sinc.c+25−9
@@ -53,8 +53,7 @@ typedef struct · 52 unmodified lines
53 /* Sure hope noone does more than 128 channels at once. */53 /* Sure hope noone does more than 128 channels at once. */
54 double left_calc [128], right_calc [128] ;54 double left_calc [128], right_calc [128] ;
55 55
56 /* C99 struct flexible array. */56 float *buffer ;
57 float buffer [] ;
58} SINC_FILTER ;57} SINC_FILTER ;
59 58
60static enum SRC_ERR sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data) ;59static enum SRC_ERR sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data) ;
@@ -220,10 +219,16 @@ sinc_set_converter (SRC_STATE *state, int src_enum) · 159 unmodified lines
220 temp_filter.b_len *= state->channels ;219 temp_filter.b_len *= state->channels ;
221 temp_filter.b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above220 temp_filter.b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
222 221
223 if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + state->channels))) == NULL)222 if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER))) == NULL)
224 return SRC_ERR_MALLOC_FAILED ;223 return SRC_ERR_MALLOC_FAILED ;
225 224
226 *filter = temp_filter ;225 *filter = temp_filter ;
226 filter->buffer = calloc (temp_filter.b_len + state->channels, sizeof (float)) ;
227 if (!filter->buffer)
228 { free (filter) ;
229 return SRC_ERR_MALLOC_FAILED ;
230 } ;
231
227 memset (&temp_filter, 0xEE, sizeof (temp_filter)) ;232 memset (&temp_filter, 0xEE, sizeof (temp_filter)) ;
228 233
229 state->private_data = filter ;234 state->private_data = filter ;
@@ -267,12 +272,18 @@ sinc_copy (SRC_STATE *from, SRC_STATE *to) · 37 unmodified lines
267 272
268 SINC_FILTER *to_filter = NULL ;273 SINC_FILTER *to_filter = NULL ;
269 SINC_FILTER* from_filter = (SINC_FILTER*) from->private_data ;274 SINC_FILTER* from_filter = (SINC_FILTER*) from->private_data ;
270 size_t private_length = sizeof (SINC_FILTER) + sizeof (from_filter->buffer [0]) * (from_filter->b_len + from->channels) ;
271 275
272 if ((to_filter = ZERO_ALLOC (SINC_FILTER, private_length)) == NULL)276 if ((to_filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER))) == NULL)
273 return SRC_ERR_MALLOC_FAILED ;277 return SRC_ERR_MALLOC_FAILED ;
278 memcpy (to_filter, from_filter, sizeof (SINC_FILTER)) ;
279 to_filter->buffer = malloc (sizeof (float) * (from_filter->b_len + from->channels)) ;
280 if (!to_filter->buffer)
281 {
282 free (to_filter) ;
283 return SRC_ERR_MALLOC_FAILED ;
284 }
285 memcpy (to_filter->buffer, from_filter->buffer, sizeof (float) * (from_filter->b_len + from->channels)) ;
274 286
275 memcpy (to_filter, from_filter, private_length) ;
276 to->private_data = to_filter ;287 to->private_data = to_filter ;
277 288
278 return SRC_ERR_NO_ERROR ;289 return SRC_ERR_NO_ERROR ;
@@ -1150,10 +1161,15 @@ sinc_close (SRC_STATE *state) · 871 unmodified lines
1150{1161{
1151 if (state)1162 if (state)
1152 {1163 {
1153 if (state->private_data)1164 SINC_FILTER *sinc = (SINC_FILTER *) state->private_data ;
1165 if (sinc)
1154 {1166 {
1155 free (state->private_data) ;1167 if (sinc->buffer)
1156 state->private_data = NULL ;1168 { free (sinc->buffer) ;
1169 sinc->buffer = NULL ;
1170 } ;
1171 free (sinc) ;
1172 sinc = NULL ;
1157 }1173 }
1158 }1174 }
1159} /* sinc_close */1175} /* sinc_close */

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