I'm running through a program and although the code is working fine, Valgrind is showing an 'Invalid write of Size 1' and Address 0x1ffefffa00 is on thread 1's stack.This has happened using both strchr
and strchrn
, another function in the program.
I've tried using index to locate the comma, as well as strchr
and my strchr
functions but all keep returning the same warning in Valgrind
typedef struct data_s Data;
struct data_s {
float temperature;
int year;
int month;
int day;
};
char* getData(FILE* filename) {
char buffer[INPUT_LINE_MAX];
char* dataLine = fgets(buffer, INPUT_LINE_MAX, filename);
return dataLine;
}
Data* buildData(FILE* filename) {
char* readLine = getData(filename);
Data* new = malloc(sizeof(Data) + 1);
char* comma1 = strchr(readLine, ',');
the rest of the code below comma1
is irrelevant