Skip to content

Commit 70ce734

Browse files
authored
init arrays with NULL
1 parent e37fb71 commit 70ce734

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/Audio.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Created on: Oct 26.2018
55
*
6-
* Version 3.0.1q
7-
* Updated on: May 02.2023
6+
* Version 3.0.1r
7+
* Updated on: May 03.2023
88
* Author: Wolle (schreibfaul1)
99
*
1010
*/
@@ -2070,7 +2070,7 @@ int Audio::read_M4A_Header(uint8_t *data, size_t len) {
20702070
offset = specialIndexOf(data, info[i], len, true); // seek info[] with '\0'
20712071
if(offset>0) {
20722072
offset += 19; if(*(data + offset) == 0) offset ++;
2073-
char value[256];
2073+
char value[256] = {0};
20742074
size_t tmp = strlen((const char*)data + offset);
20752075
if(tmp > 254) tmp = 254;
20762076
memcpy(value, (data + offset), tmp);
@@ -2381,7 +2381,7 @@ bool Audio::readPlayListData() {
23812381

23822382
// reads the content of the playlist and stores it in the vector m_contentlength
23832383
// m_contentlength is a table of pointers to the lines
2384-
char pl[512]; // playlistLine
2384+
char pl[512] = {0}; // playlistLine
23852385
uint32_t ctl = 0;
23862386
int lines = 0;
23872387
// delete all memory in m_playlistContent
@@ -3322,7 +3322,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
33223322
if(getDatamode() != HTTP_RESPONSE_HEADER) return false;
33233323
if(_client->available() == 0) return false;
33243324

3325-
char rhl[512]; // responseHeaderline
3325+
char rhl[512] = {0}; // responseHeaderline
33263326
bool ct_seen = false;
33273327
uint32_t ctime = millis();
33283328
uint32_t timeout = 2500; // ms
@@ -5195,15 +5195,15 @@ void Audio::seek_m4a_ilst(){
51955195
struct m4a_Atom{
51965196
int pos;
51975197
int size;
5198-
char name[5];
5198+
char name[5] = {0};
51995199
} atom, at, tmp;
52005200

52015201
// c99 has no inner functions, lambdas are only allowed from c11, please don't use ancient compiler
52025202
auto atomItems = [&](uint32_t startPos){ // lambda, inner function
5203-
char tmp[5];
5203+
char temp[5] = {0};
52045204
audiofile.seek(startPos);
5205-
audiofile.readBytes(tmp, 4);
5206-
atom.size = bigEndian((uint8_t*)tmp, 4);
5205+
audiofile.readBytes(temp, 4);
5206+
atom.size = bigEndian((uint8_t*)temp, 4);
52075207
if(!atom.size) atom.size = 4; // has no data, length is 0
52085208
audiofile.readBytes(atom.name, 4);
52095209
atom.name[4] = '\0';
@@ -5254,17 +5254,18 @@ void Audio::seek_m4a_ilst(){
52545254
audiofile.seek(seekpos);
52555255
audiofile.read(data, len);
52565256

5257-
int offset;
5257+
int offset = 0;
52585258
for(int i=0; i < 12; i++){
52595259
offset = specialIndexOf(data, info[i], len, true); // seek info[] with '\0'
5260-
if(offset>0) {
5260+
if(offset > 0) {
52615261
offset += 19; if(*(data + offset) == 0) offset ++;
5262-
char value[256];
5263-
size_t tmp = strlen((const char*)data + offset);
5264-
if(tmp > 254) tmp = 254;
5265-
memcpy(value, (data + offset), tmp);
5266-
value[tmp] = 0;
5267-
m_chbuf[0] = 0;
5262+
char value[256] = {0};
5263+
size_t temp = strlen((const char*)data + offset);
5264+
if(temp > 254) temp = 254;
5265+
memcpy(value, (data + offset), temp);
5266+
log_w("value %s, temp %i", value, temp);
5267+
value[temp] = '\0';
5268+
m_chbuf[0] = '\0';
52685269
if(i == 0) sprintf(m_chbuf, "Title: %s", value);
52695270
if(i == 1) sprintf(m_chbuf, "Artist: %s", value);
52705271
if(i == 2) sprintf(m_chbuf, "Album: %s", value);
@@ -5310,15 +5311,16 @@ void Audio::seek_m4a_stsz(){
53105311
struct m4a_Atom{
53115312
int pos;
53125313
int size;
5313-
char name[5];
5314+
char name[5] = {0};
53145315
} atom, at, tmp;
53155316

53165317
// c99 has no inner functions, lambdas are only allowed from c11, please don't use ancient compiler
53175318
auto atomItems = [&](uint32_t startPos){ // lambda, inner function
5318-
char tmp[5];
5319+
char temp[5] = {0};
53195320
audiofile.seek(startPos);
5320-
audiofile.readBytes(tmp, 4);
5321-
atom.size = bigEndian((uint8_t*)tmp, 4);
5321+
audiofile.readBytes(temp, 4);
5322+
log_w("be1");
5323+
atom.size = bigEndian((uint8_t*)temp, 4);
53225324
if(!atom.size) atom.size = 4; // has no data, length is 0
53235325
audiofile.readBytes(atom.name, 4);
53245326
atom.name[4] = '\0';
@@ -5331,7 +5333,7 @@ void Audio::seek_m4a_stsz(){
53315333
uint32_t seekpos = 0;
53325334
uint32_t filesize = getFileSize();
53335335
char name[6][5] = {"moov", "trak", "mdia", "minf", "stbl", "stsz"};
5334-
char noe[4];
5336+
char noe[4] = {0};
53355337

53365338
if(!audiofile) return; // guard
53375339

@@ -5354,6 +5356,7 @@ void Audio::seek_m4a_stsz(){
53545356
seekpos += 8; // 1 byte version + 3 bytes flags + 4 bytes sample size
53555357
audiofile.seek(seekpos);
53565358
audiofile.readBytes(noe, 4); //number of entries
5359+
log_w("be1");
53575360
m_stsz_numEntries = bigEndian((uint8_t*)noe, 4);
53585361
if(m_f_Log) log_i("number of entries in stsz: %d", m_stsz_numEntries);
53595362
m_stsz_position = seekpos + 4;

src/Audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Created on: Oct 28,2018
55
*
6-
* Version 3.0.1p
7-
* Updated on: Apr 19,2023
6+
* Version 3.0.1r
7+
* Updated on: May 03,2023
88
* Author: Wolle (schreibfaul1)
99
*/
1010

0 commit comments

Comments
 (0)