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_linear.c (1 of 3 files). Show all

Unified · Split

src/src_linear.c+34−11
@@ -31,7 +31,7 @@ typedef struct · 30 unmodified lines
31 bool dirty ;31 bool dirty ;
32 long in_count, in_used ;32 long in_count, in_used ;
33 long out_count, out_gen ;33 long out_count, out_gen ;
34 float last_value [] ;34 float *last_value ;
35} LINEAR_DATA ;35} LINEAR_DATA ;
36 36
37/*----------------------------------------------------------------------------------------37/*----------------------------------------------------------------------------------------
@@ -160,7 +160,8 @@ linear_get_description (int src_enum) · 122 unmodified lines
160 160
161enum SRC_ERR161enum SRC_ERR
162linear_set_converter (SRC_STATE *state, int src_enum)162linear_set_converter (SRC_STATE *state, int src_enum)
163{ LINEAR_DATA *priv = NULL ;163{
164 LINEAR_DATA *priv = NULL ;
164 165
165 if (src_enum != SRC_LINEAR)166 if (src_enum != SRC_LINEAR)
166 return SRC_ERR_BAD_CONVERTER ;167 return SRC_ERR_BAD_CONVERTER ;
@@ -168,13 +169,24 @@ linear_set_converter (SRC_STATE *state, int src_enum) · 1 unmodified line
168 linear_close (state) ;169 linear_close (state) ;
169 170
170 if (state->private_data == NULL)171 if (state->private_data == NULL)
171 { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;172 {
172 state->private_data = priv ;173 priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv)) ;
173 } ;174 if (priv)
175 {
176 priv->last_value = calloc (state->channels, sizeof (float)) ;
177 if (!priv->last_value)
178 {
179 free (priv) ;
180 priv = NULL ;
181 }
182 }
183 }
174 184
175 if (priv == NULL)185 if (priv == NULL)
176 return SRC_ERR_MALLOC_FAILED ;186 return SRC_ERR_MALLOC_FAILED ;
177 187
188 state->private_data = priv ;
189
178 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;190 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
179 191
180 state->const_process = linear_vari_process ;192 state->const_process = linear_vari_process ;
@@ -213,12 +225,18 @@ linear_copy (SRC_STATE *from, SRC_STATE *to) · 32 unmodified lines
213 225
214 LINEAR_DATA *to_priv = NULL ;226 LINEAR_DATA *to_priv = NULL ;
215 LINEAR_DATA* from_priv = (LINEAR_DATA*) from->private_data ;227 LINEAR_DATA* from_priv = (LINEAR_DATA*) from->private_data ;
216 size_t private_size = sizeof (*to_priv) + from->channels * sizeof (float) ;228 if ((to_priv = ZERO_ALLOC (LINEAR_DATA, sizeof (LINEAR_DATA))) == NULL)
229 return SRC_ERR_MALLOC_FAILED ;
217 230
218 if ((to_priv = ZERO_ALLOC (LINEAR_DATA, private_size)) == NULL)231 memcpy (to_priv, from_priv, sizeof (LINEAR_DATA)) ;
232 to_priv->last_value = malloc (sizeof (float) * from->channels) ;
233 if (!to_priv->last_value)
234 {
235 free (to_priv) ;
219 return SRC_ERR_MALLOC_FAILED ;236 return SRC_ERR_MALLOC_FAILED ;
237 }
238 memcpy (to_priv->last_value, from_priv->last_value, sizeof (float) * from->channels) ;
220 239
221 memcpy (to_priv, from_priv, private_size) ;
222 to->private_data = to_priv ;240 to->private_data = to_priv ;
223 241
224 return SRC_ERR_NO_ERROR ;242 return SRC_ERR_NO_ERROR ;
@@ -229,10 +247,15 @@ linear_close (SRC_STATE *state) · 4 unmodified lines
229{247{
230 if (state)248 if (state)
231 {249 {
232 if (state->private_data)250 LINEAR_DATA *linear = (LINEAR_DATA *) state->private_data ;
251 if (linear)
233 {252 {
234 free (state->private_data) ;253 if (linear->last_value)
235 state->private_data = NULL ;254 { free (linear->last_value) ;
255 linear->last_value = NULL ;
256 } ;
257 free (linear) ;
258 linear = NULL ;
236 }259 }
237 }260 }
238} /* linear_close */261} /* linear_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