Skip to content

Commit

Permalink
On MSCV, an unsigned long is 4 bytes (32 bits), not 8 bytes. Thus the…
Browse files Browse the repository at this point in the history
… alignment code using ~0x7UL truncates pointers resulting in crashes. Instead, use unsigned long long wich is 8 bytes.
  • Loading branch information
cfis committed May 18, 2020
1 parent c674683 commit 7bbbce2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ext/ffi_c/Buffer.c
Expand Up @@ -114,7 +114,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
}

/* ensure the memory is aligned on at least a 8 byte boundary */
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL);
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL);

if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
memset(p->memory.address, 0, p->memory.size);
Expand Down Expand Up @@ -154,7 +154,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
return Qnil;
}

dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL);
dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL);
dst->memory.size = src->size;
dst->memory.typeSize = src->typeSize;

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/MemoryPointer.c
Expand Up @@ -112,7 +112,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
p->memory.typeSize = (int) size;
p->memory.size = msize;
/* ensure the memory is aligned on at least a 8 byte boundary */
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);;
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7ULL);
p->allocated = true;

if (clear && p->memory.size > 0) {
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/Pointer.c
Expand Up @@ -183,7 +183,7 @@ ptr_initialize_copy(VALUE self, VALUE other)

dst->allocated = true;
dst->autorelease = true;
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL);
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7ULL);
dst->memory.size = src->size;
dst->memory.typeSize = src->typeSize;

Expand Down

0 comments on commit 7bbbce2

Please sign in to comment.