Skip to content

Commit 8b4bbbd

Browse files
authored
Merge pull request #1170 from schreibfaul1/clearing-an-object-of-non-trivial-type
fix Clearing an object of non trivial type
2 parents db803be + 2c6ffca commit 8b4bbbd

File tree

7 files changed

+106
-163
lines changed

7 files changed

+106
-163
lines changed

src/Audio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
44274427
return false;
44284428
}
44294429

4430-
memset(&m_phreh, 0, sizeof(m_phreh));
4430+
m_phreh.reset();
44314431
m_phreh.ctime = millis();
44324432
m_phreh.timeout = 4500; // ms
44334433

@@ -6217,7 +6217,7 @@ bool Audio::ts_parsePacket(uint8_t* packet, uint8_t* packetStart, uint8_t* packe
62176217

62186218
if (packet == NULL) {
62196219
if (log) AUDIO_LOG_WARN("parseTS reset");
6220-
memset(&m_tspp, 0, sizeof(audiolib::tspp_t));
6220+
m_tspp.reset();
62216221
return true;
62226222
}
62236223

src/audiolib_structs.hpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,18 @@ struct ifCh_t { // used in IIR_filterChain0, 1, 2
182182
int16_t iir_out2[2];
183183
};
184184

185-
struct tspp_t { // used in ts_parsePacket
186-
int pidNumber = 0;
187-
int pids[4]; // PID_ARRAY_LEN
188-
int PES_DataLength = 0;
189-
int pidOfAAC = 0;
190-
uint8_t fillData = 0;
191-
};
185+
typedef struct _tspp { // used in ts_parsePacket
186+
int pidNumber{};
187+
int pids[4]{}; // PID_ARRAY_LEN
188+
int PES_DataLength{};
189+
int pidOfAAC{};
190+
uint8_t fillData{};
191+
192+
void reset() {
193+
// Default-initialize alles neu (inklusive Array)
194+
*this = _tspp{};
195+
}
196+
}tspp_t;
192197

193198
struct pwst_t { // used in processWebStream
194199
uint16_t maxFrameSize;
@@ -287,14 +292,19 @@ typedef struct _rflh { // used in read_FLAC_Header
287292
}
288293
} rflh_t;
289294

290-
struct phreh_t { // used in parseHttpResponseHeader
291-
uint32_t ctime;
292-
uint32_t timeout;
293-
uint32_t stime;
294-
uint32_t bitrate;
295-
bool f_time = false;
296-
bool f_icy_data = false;
297-
};
295+
typedef struct _phreh { // used in parseHttpResponseHeader
296+
uint32_t ctime{};
297+
uint32_t timeout{};
298+
uint32_t stime{};
299+
uint32_t bitrate{};
300+
bool f_time{};
301+
bool f_icy_data{};
302+
303+
void reset() {
304+
// Default-initialize alles neu (inklusive Array)
305+
*this = _phreh{};
306+
}
307+
} phreh_t;
298308

299309
struct phrah_t { // used in parseHttpRangeHeader
300310
uint32_t ctime;

src/opus_decoder/silk.cpp

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,66 +2787,6 @@ void SilkDecoder::silk_PLC_glue_frames(uint8_t n, int16_t frame[], int32_t lengt
27872787
}
27882788
}
27892789
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
2790-
/* Downsample by a factor 2/3, low quality */
2791-
void SilkDecoder::silk_resampler_down2_3(int32_t* S, /* I/O State vector [ 6 ] */
2792-
int16_t* out, /* O Output signal [ floor(2*inLen/3) ] */
2793-
const int16_t* in, /* I Input signal [ inLen ] */
2794-
int32_t inLen /* I Number of input samples */
2795-
) {
2796-
int32_t nSamplesIn, counter, res_Q6;
2797-
int32_t* buf_ptr;
2798-
2799-
ps_ptr<int32_t>buf; buf.alloc_array(RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR);
2800-
2801-
/* Copy buffered samples to start of buffer */
2802-
memcpy(buf.get(), S, ORDER_FIR * sizeof(int32_t));
2803-
2804-
/* Iterate over blocks of frameSizeIn input samples */
2805-
while(1) {
2806-
nSamplesIn = silk_min(inLen, RESAMPLER_MAX_BATCH_SIZE_IN);
2807-
2808-
/* Second-order AR filter (output in Q8) */
2809-
silk_resampler_private_AR2(&S[ORDER_FIR], &buf[ORDER_FIR], in, silk_Resampler_2_3_COEFS_LQ, nSamplesIn);
2810-
2811-
/* Interpolate filtered signal */
2812-
buf_ptr = buf.get();
2813-
counter = nSamplesIn;
2814-
while(counter > 2) {
2815-
/* Inner product */
2816-
res_Q6 = silk_SMULWB(buf_ptr[0], silk_Resampler_2_3_COEFS_LQ[2]);
2817-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[1], silk_Resampler_2_3_COEFS_LQ[3]);
2818-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[2], silk_Resampler_2_3_COEFS_LQ[5]);
2819-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[3], silk_Resampler_2_3_COEFS_LQ[4]);
2820-
2821-
/* Scale down, saturate and store in output array */
2822-
*out++ = (int16_t)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6));
2823-
2824-
res_Q6 = silk_SMULWB(buf_ptr[1], silk_Resampler_2_3_COEFS_LQ[4]);
2825-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[2], silk_Resampler_2_3_COEFS_LQ[5]);
2826-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[3], silk_Resampler_2_3_COEFS_LQ[3]);
2827-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[4], silk_Resampler_2_3_COEFS_LQ[2]);
2828-
2829-
/* Scale down, saturate and store in output array */
2830-
*out++ = (int16_t)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6));
2831-
2832-
buf_ptr += 3;
2833-
counter -= 3;
2834-
}
2835-
2836-
in += nSamplesIn;
2837-
inLen -= nSamplesIn;
2838-
2839-
if(inLen > 0) {
2840-
/* More iterations to do; copy last part of filtered signal to beginning of buffer */
2841-
memcpy(buf.get(), &buf[nSamplesIn], ORDER_FIR * sizeof(int32_t));
2842-
}
2843-
else { break; }
2844-
}
2845-
2846-
/* Copy last part of filtered signal to the state for the next call */
2847-
memcpy(S, &buf[nSamplesIn], ORDER_FIR * sizeof(int32_t));
2848-
}
2849-
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
28502790
/* Downsample by a factor 2 */
28512791
void SilkDecoder::silk_resampler_down2(int32_t* S, /* I/O State vector [ 2 ] */
28522792
int16_t* out, /* O Output signal [ floor(len/2) ] */
@@ -3084,7 +3024,11 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30843024
int32_t nSamplesIn;
30853025
int32_t max_index_Q16, index_increment_Q16;
30863026

3087-
ps_ptr<int16_t>buf; buf.alloc_array(2 * S->batchSize + RESAMPLER_ORDER_FIR_12);
3027+
ps_ptr<int16_t> buf;
3028+
int32_t buf_size = 2 * S->batchSize + RESAMPLER_ORDER_FIR_12;
3029+
if (!buf.alloc_array(buf_size)) {
3030+
return; // Allocation failed
3031+
}
30883032

30893033
/* Copy buffered samples to start of buffer */
30903034
memcpy(buf.get(), S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
@@ -3095,7 +3039,7 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30953039
nSamplesIn = silk_min(inLen, S->batchSize);
30963040

30973041
/* Upsample 2x */
3098-
silk_resampler_private_up2_HQ(S->sIIR, &buf[RESAMPLER_ORDER_FIR_12], in, nSamplesIn);
3042+
silk_resampler_private_up2_HQ(S->sIIR, buf.get() + RESAMPLER_ORDER_FIR_12, in, nSamplesIn);
30993043

31003044
max_index_Q16 = silk_LSHIFT32(nSamplesIn, 16 + 1); /* + 1 because 2x upsampling */
31013045
out = silk_resampler_private_IIR_FIR_INTERPOL(out, buf.get(), max_index_Q16, index_increment_Q16);
@@ -3104,13 +3048,19 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
31043048

31053049
if(inLen > 0) {
31063050
/* More iterations to do; copy last part of filtered signal to beginning of buffer */
3107-
memcpy(buf.get(), &buf[nSamplesIn << 1], RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3051+
int32_t src_offset = nSamplesIn << 1;
3052+
if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3053+
memcpy(buf.get(), buf.get() + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3054+
}
31083055
}
31093056
else { break; }
31103057
}
31113058

31123059
/* Copy last part of filtered signal to the state for the next call */
3113-
memcpy(S->sFIR.i16, &buf[nSamplesIn << 1], RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3060+
int32_t src_offset = nSamplesIn << 1;
3061+
if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3062+
memcpy(S->sFIR.i16, buf.get() + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3063+
}
31143064
}
31153065
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
31163066
/* Upsample by a factor 2, high quality. Uses 2nd order allpass filters for the 2x upsampling, followed by a */

src/opus_decoder/silk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ class SilkDecoder{
272272
void silk_PLC_update(uint8_t n);
273273
void silk_PLC_energy(int32_t *energy1, int32_t *shift1, int32_t *energy2, int32_t *shift2, const int32_t *exc_Q14, const int32_t *prevGain_Q10, int subfr_length, int nb_subfr);
274274
void silk_PLC_conceal(uint8_t n, int16_t frame[]);
275-
void silk_resampler_down2_3(int32_t *S, int16_t *out, const int16_t *in, int32_t inLen);
276275
void silk_resampler_down2(int32_t *S, int16_t *out, const int16_t *in, int32_t inLen);
277276
void silk_resampler_private_AR2(int32_t S[], int32_t out_Q8[], const int16_t in[], const int16_t A_Q14[], int32_t len);
278277
int16_t *silk_resampler_private_down_FIR_INTERPOL(int16_t *out, int32_t *buf, const int16_t *FIR_Coefs, int32_t FIR_Order, int32_t FIR_Fracs, int32_t max_index_Q16, int32_t index_increment_Q16);

src/psram_unique_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class ps_ptr {
209209
bool alloc_array(std::size_t count, const char* alloc_name = nullptr) {
210210
if (alloc_name) { set_name(alloc_name); }
211211
bool res = alloc(sizeof(T) * count);
212-
clear();
212+
// clear();
213213
return res;
214214
}
215215
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

0 commit comments

Comments
 (0)