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
3131 bool dirty ;
3232 long in_count, in_used ;
3333 long out_count, out_gen ;
34− float last_value [] ;
34+ float *last_value ;
3535 } LINEAR_DATA ;
3636
3737 /*----------------------------------------------------------------------------------------
@@ -160,7 +160,8 @@ linear_get_description (int src_enum) · 122 unmodified lines
160160
161161 enum SRC_ERR
162162 linear_set_converter (SRC_STATE *state, int src_enum)
163−{ LINEAR_DATA *priv = NULL ;
163+{
164+ LINEAR_DATA *priv = NULL ;
164165
165166 if (src_enum != SRC_LINEAR)
166167 return SRC_ERR_BAD_CONVERTER ;
@@ -168,13 +169,24 @@ linear_set_converter (SRC_STATE *state, int src_enum) · 1 unmodified line
168169 linear_close (state) ;
169170
170171 if (state->private_data == NULL)
171− { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
172− state->private_data = priv ;
173− } ;
172+ {
173+ priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv)) ;
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+ }
174184
175185 if (priv == NULL)
176186 return SRC_ERR_MALLOC_FAILED ;
177187
188+ state->private_data = priv ;
189+
178190 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
179191
180192 state->const_process = linear_vari_process ;
@@ -213,12 +225,18 @@ linear_copy (SRC_STATE *from, SRC_STATE *to) · 32 unmodified lines
213225
214226 LINEAR_DATA *to_priv = NULL ;
215227 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 ;
217230
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) ;
219236 return SRC_ERR_MALLOC_FAILED ;
237+ }
238+ memcpy (to_priv->last_value, from_priv->last_value, sizeof (float) * from->channels) ;
220239
221− memcpy (to_priv, from_priv, private_size) ;
222240 to->private_data = to_priv ;
223241
224242 return SRC_ERR_NO_ERROR ;
@@ -229,10 +247,15 @@ linear_close (SRC_STATE *state) · 4 unmodified lines
229247 {
230248 if (state)
231249 {
232− if (state->private_data)
250+ LINEAR_DATA *linear = (LINEAR_DATA *) state->private_data ;
251+ if (linear)
233252 {
234− free (state->private_data) ;
235− state->private_data = NULL ;
253+ if (linear->last_value)
254+ { free (linear->last_value) ;
255+ linear->last_value = NULL ;
256+ } ;
257+ free (linear) ;
258+ linear = NULL ;
236259 }
237260 }
238261 } /* 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