Code: Select all
class CSV
{
private:
/* data */
char* const m_buffer{nullptr};
const uint16_t m_number_of_columns;
public:
CSV(size_t size, uint16_t number_of_column);
~CSV();
//This function finds a row through its number.
CSV_Row row_get (uint16_t row_number){
char *buf = find_start_of_row(row_number); //If row_number don't be valid returns "nullptr"
Serial.println("Debug:1");
//The error will occur here, when send nullptr to CSV_Row constructore.
if (nullptr == buf) return (CSV_Row(nullptr));
Serial.println("Debug:2");
return CSV_Row(this, buf);
};
friend class CSV_Row;
};
Code: Select all
class CSV_Row
{
private:
/* data */
CSV* m_csv;
const char**m_cells{nullptr};
char* m_location{nullptr};
public:
CSV_Row(CSV* csv, char* const location = nullptr)
{
Serial.println("Debug:3");
if (nullptr != csv)
{
m_csv = csv;
m_location = location;
m_cells = new const char*[m_csv->m_number_of_columns];
Serial.println("Debug:4");
}
};
~CSV_Row();
};
Code: Select all
#define VALID
CSV my_csv(1000, 4);
void setup (){
/*I initialize the my_csv here, its content is :
col1,col2,col3,col4
ce11,ce12,ce13,ce14
ce21,ce22,ce23,ce24
*/
#ifdef VALID
CSV_Row my_row = my_csv.row_get(1); //Use method with valid argument
#else
CSV_Row my_row = my_csv.row_get(6); //Use method with invalid argument
#endif
Serial.println("Debug:5");
}
void loop()
{
}
and when i use those method with invalid argument the program will crash and serial monitor show :Debug:1
Debug:2
Debug:3
Debug:4
Debug:5
What is wrong with my code?Debug:1
Debug:3
Debug:5
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
I remove additional data