Skip to content

Commit

Permalink
better overflow check. fix msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
wjblanke committed Jun 5, 2020
1 parent efbbd55 commit ce388d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/plotter_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class DiskPlotter {

// These variables are used in the WriteParkToFile method. They are preallocatted here
// to save time.
parkToFileBytes = new uint8_t[CalculateLinePointSize(k)+CalculateStubsSize(k)+2+CalculateMaxDeltasSize(k, 1)];
parkToFileBytesSize = CalculateLinePointSize(k)+CalculateStubsSize(k)+2+CalculateMaxDeltasSize(k, 1);
parkToFileBytes = new uint8_t[parkToFileBytesSize];

assert(id_len == kIdLen);

Expand Down Expand Up @@ -260,6 +261,7 @@ class DiskPlotter {
private:
uint64_t memorySize;
uint8_t* parkToFileBytes;
uint32_t parkToFileBytesSize;

// Writes the plot file header to a file
uint32_t WriteHeader(FileDisk& plot_Disk, uint8_t k, const uint8_t* id, const uint8_t* memo,
Expand Down Expand Up @@ -1018,7 +1020,9 @@ class DiskPlotter {
index+=encoded_size;
}

assert((uint32_t)(index-parkToFileBytes) <= parkToFileBytes.size());
if((uint32_t)(index-parkToFileBytes) > parkToFileBytesSize)
std::cout << "index-parkToFileBytes " << index-parkToFileBytes << " parkToFileBytesSize " << parkToFileBytesSize << std::endl;

final_disk.Write(writer, (uint8_t *)parkToFileBytes, index-parkToFileBytes);
}

Expand Down
12 changes: 10 additions & 2 deletions src/sort_on_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class FileDisk : public Disk {
inline void Read(uint64_t begin, uint8_t* memcache, uint64_t length) override {
// Seek, read, and replace into memcache
if((!bReading)||(begin!=readPos)) {
fseek(f_,begin,SEEK_SET);
#ifdef WIN32
_fseeki64(f_,begin,SEEK_SET);
#else
fseek(f_, begin, SEEK_SET);
#endif
bReading=true;
}
fread(reinterpret_cast<char*>(memcache), sizeof(uint8_t), length, f_);
Expand All @@ -119,7 +123,11 @@ class FileDisk : public Disk {
inline void Write(uint64_t begin, const uint8_t* memcache, uint64_t length) override {
// Seek and write from memcache
if((bReading)||(begin!=writePos)) {
fseek(f_,begin,SEEK_SET);
#ifdef WIN32
_fseeki64(f_,begin,SEEK_SET);
#else
fseek(f_, begin, SEEK_SET);
#endif
bReading=false;
}
fwrite(reinterpret_cast<const char*>(memcache), sizeof(uint8_t), length, f_);
Expand Down

0 comments on commit ce388d7

Please sign in to comment.