Skip to content

Commit

Permalink
src/memory.cpp: Fix sizeof() (google#221)
Browse files Browse the repository at this point in the history
This was using `sizeof(size_t)`, when it should have been `sizeof(void*)`. While these are usually equal, I don't think there's any guarantees for this.

Fixes: google#220
  • Loading branch information
ben-clayton authored Mar 2, 2022
1 parent 166fc60 commit 9929747
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ inline void* alignedMalloc(size_t alignment, size_t size) {
// alignedFree() frees memory allocated by alignedMalloc.
inline void alignedFree(void* ptr, size_t size) {
void* base;
memcpy(&base, reinterpret_cast<uint8_t*>(ptr) + size, sizeof(size_t));
memcpy(&base, reinterpret_cast<uint8_t*>(ptr) + size, sizeof(void*));
free(base);
}

Expand Down

0 comments on commit 9929747

Please sign in to comment.