From 748055996aadd3b8129ebb3dd3a50a1853f62f2f Mon Sep 17 00:00:00 2001 From: Renge Date: Fri, 25 Mar 2022 20:50:24 -0400 Subject: [PATCH] fix: xor with not --- hw3/src/main.c | 16 ++++++---------- hw3/src/sfmm.c | 8 +++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hw3/src/main.c b/hw3/src/main.c index 0554122..55bf4b8 100644 --- a/hw3/src/main.c +++ b/hw3/src/main.c @@ -2,16 +2,12 @@ #include "sfmm.h" int main(int argc, char const *argv[]) { - sf_set_magic(0x0); - size_t sz_w = 8, sz_x = 200, sz_y = 300, sz_z = 4; - /* void *w = */ sf_malloc(sz_w); - void *x = sf_malloc(sz_x); - void *y = sf_malloc(sz_y); - /* void *z = */ sf_malloc(sz_z); - - sf_free(y); - sf_free(x); - // sf_show_heap(); + sf_set_magic(0x0); + sf_errno = 0; + size_t sz = sizeof(int); + int *x = sf_malloc(sz); + + *x = 4; return EXIT_SUCCESS; } diff --git a/hw3/src/sfmm.c b/hw3/src/sfmm.c index e2d1ef6..387f9b8 100644 --- a/hw3/src/sfmm.c +++ b/hw3/src/sfmm.c @@ -89,6 +89,7 @@ void *sf_malloc(sf_size_t size) sf_block *block = split_block(ptr, min_size); sf_size_t block_size = get_block_size(block->header); set_entire_header(block, size, block_size, 1, get_prv_alloc(block->header), 0); + // sf_show_block(block); return block->body.payload; } } @@ -254,6 +255,7 @@ void set_entire_header(sf_block *block, sf_size_t paylod_size, sf_size_t block_s set_block_size(block, block_size); set_prv_alloc(block, is_prv_alloc); set_in_qklst(block, is_in_qklst); + // sf_show_block(block); } void set_payload_size(sf_block *block, sf_size_t payload_size) @@ -282,7 +284,7 @@ void set_alloc(sf_block *block, sf_size_t is_alloc) } else { - value &= ~alloc; + value &= (~((uint64_t)alloc)); } set_header(block, value); // block->header ^= MAGIC; @@ -298,7 +300,7 @@ void set_prv_alloc(sf_block *block, sf_size_t is_prv_allc) } else { - value &= ~prv_alloc; + value &= (~((uint64_t)prv_alloc)); } set_header(block, value); // block->header ^= MAGIC; @@ -314,7 +316,7 @@ void set_in_qklst(sf_block *block, sf_size_t is_in_qklst) } else { - value &= ~in_qklst; + value &= (~((uint64_t)in_qklst)); } set_header(block, value); // block->header ^= MAGIC;