Skip to content

Commit

Permalink
Merge pull request #77 from mistersandman/fix_gcc_4_8
Browse files Browse the repository at this point in the history
Fix compilation with gcc 4.8
  • Loading branch information
canterberry authored Dec 5, 2019
2 parents 14ceb0c + a51f2fb commit c044fc8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ class SHA3Hash: public ObjectWrap {
static constexpr size_t state_buf_size = sizeof(hashState) + std::alignment_of<hashState>::value - 1;
char state_buf[state_buf_size];

// remove this function in favor of std::align once gcc 5.1 is the minimal required compiler version
void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
return reinterpret_cast<char*>(reinterpret_cast<size_t>(static_cast<char*>(ptr) + (alignment - 1)) & (~alignment + 1));
}

SHA3Hash() {
void* buf = reinterpret_cast<void*>(state_buf);
size_t buf_size = state_buf_size;
void* aligned_buf = std::align(std::alignment_of<hashState>::value, sizeof(hashState), buf, buf_size);
void* aligned_buf = align(std::alignment_of<hashState>::value, sizeof(hashState), buf, buf_size);
state = new(aligned_buf) hashState();
}

Expand Down

0 comments on commit c044fc8

Please sign in to comment.