Mem: Allow serializing of more than INT_MAX bytes
Despite gzwrite taking an unsigned for length, it returns an int for bytes written; gzwrite fails if (int)len < 0. Because of this, call gzwrite with len no larger than INT_MAX: write in blocks of INT_MAX if data to be written is larger than INT_MAX.
This commit is contained in:
parent
21d4d50ba1
commit
9e0edbcea8
1 changed files with 12 additions and 3 deletions
|
@ -51,6 +51,7 @@
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <climits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -486,9 +487,17 @@ AbstractMemory::serialize(ostream &os)
|
||||||
fatal("Insufficient memory to allocate compression state for %s\n",
|
fatal("Insufficient memory to allocate compression state for %s\n",
|
||||||
filename);
|
filename);
|
||||||
|
|
||||||
if (gzwrite(compressedMem, pmemAddr, size()) != (int)size()) {
|
uint64_t pass_size = 0;
|
||||||
fatal("Write failed on physical memory checkpoint file '%s'\n",
|
// gzwrite fails if (int)len < 0 (gzwrite returns int)
|
||||||
filename);
|
for (uint64_t written = 0; written < size(); written += pass_size) {
|
||||||
|
pass_size = (uint64_t)INT_MAX < (size() - written) ?
|
||||||
|
(uint64_t)INT_MAX : (size() - written);
|
||||||
|
|
||||||
|
if (gzwrite(compressedMem, pmemAddr + written,
|
||||||
|
(unsigned int) pass_size) != (int)pass_size) {
|
||||||
|
fatal("Write failed on physical memory checkpoint file '%s'\n",
|
||||||
|
filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gzclose(compressedMem))
|
if (gzclose(compressedMem))
|
||||||
|
|
Loading…
Reference in a new issue