J
Julien
Hello,
I used cppcheck to detect problems and had this :
(warning) scanf without field width limits can crash with huge input data
void read_cputime(double& cpu) {
long int c;
cpu = 0;
FILE* f = fopen(CPU_TIME, "r");
if (!f) return;
int n = fscanf(f, "%ld",&c); <-- pb detected
fclose(f);
if (n != 1) return;
cpu = c;
}
First I thought about adding a number in the format :
int n = fscanf(f, "%4ld",&c);
But I want the code to be portable (it must ok for 32 bits or 64 bits).
So what to use ? A macro ? A c++ const ? C++ internal library (cin ?) ?
other ?
would a memset (c, 0, sizeof(c)) useful before ?
Julien.
I used cppcheck to detect problems and had this :
(warning) scanf without field width limits can crash with huge input data
void read_cputime(double& cpu) {
long int c;
cpu = 0;
FILE* f = fopen(CPU_TIME, "r");
if (!f) return;
int n = fscanf(f, "%ld",&c); <-- pb detected
fclose(f);
if (n != 1) return;
cpu = c;
}
First I thought about adding a number in the format :
int n = fscanf(f, "%4ld",&c);
But I want the code to be portable (it must ok for 32 bits or 64 bits).
So what to use ? A macro ? A c++ const ? C++ internal library (cin ?) ?
other ?
would a memset (c, 0, sizeof(c)) useful before ?
Julien.