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");
|
||||
if(f == NULL) return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
if(fseek(f, 0, SEEK_END) != 0)
|
||||
return false;
|
||||
data->resize(ftell(f));
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(&(*data)[0], 1, data->size(), f);
|
||||
fclose(f);
|
||||
if(fseek(f, 0, SEEK_SET) != 0)
|
||||
return false;
|
||||
if(fread(&(*data)[0], 1, data->size(), f) != data->size())
|
||||
return false;
|
||||
if(fclose(f) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -432,8 +436,10 @@ bool WriteFile(const Platform::Path &filename, const std::string &data) {
|
|||
FILE *f = OpenFile(filename, "wb");
|
||||
if(f == NULL) return false;
|
||||
|
||||
fwrite(&data[0], 1, data.size(), f);
|
||||
fclose(f);
|
||||
if(fwrite(&data[0], 1, data.size(), f) != data.size())
|
||||
return false;
|
||||
if(fclose(f) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue