Check return values of fread, etc in ReadFile/WriteFile.
parent
8f2af5b228
commit
8e4c4b0d46
|
@ -419,11 +419,15 @@ bool ReadFile(const Platform::Path &filename, std::string *data) {
|
||||||
FILE *f = OpenFile(filename, "rb");
|
FILE *f = OpenFile(filename, "rb");
|
||||||
if(f == NULL) return false;
|
if(f == NULL) return false;
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
if(fseek(f, 0, SEEK_END) != 0)
|
||||||
|
return false;
|
||||||
data->resize(ftell(f));
|
data->resize(ftell(f));
|
||||||
fseek(f, 0, SEEK_SET);
|
if(fseek(f, 0, SEEK_SET) != 0)
|
||||||
fread(&(*data)[0], 1, data->size(), f);
|
return false;
|
||||||
fclose(f);
|
if(fread(&(*data)[0], 1, data->size(), f) != data->size())
|
||||||
|
return false;
|
||||||
|
if(fclose(f) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -432,8 +436,10 @@ bool WriteFile(const Platform::Path &filename, const std::string &data) {
|
||||||
FILE *f = OpenFile(filename, "wb");
|
FILE *f = OpenFile(filename, "wb");
|
||||||
if(f == NULL) return false;
|
if(f == NULL) return false;
|
||||||
|
|
||||||
fwrite(&data[0], 1, data.size(), f);
|
if(fwrite(&data[0], 1, data.size(), f) != data.size())
|
||||||
fclose(f);
|
return false;
|
||||||
|
if(fclose(f) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue