# HG changeset patch # User June Park # Date 1767306317 28800 # Node ID d39e8860a36176b48cba0eed98352a1f57195813 # Parent 431df06b1a9be9a5241dd5bd5ae6dcd770ad40bb [Dowa] There was alignment issues rea hash key diff -r 431df06b1a9b -r d39e8860a361 dowa/BUILD --- a/dowa/BUILD Thu Jan 01 14:05:34 2026 -0800 +++ b/dowa/BUILD Thu Jan 01 14:25:17 2026 -0800 @@ -45,6 +45,6 @@ "test_folder/**", ]), # TODO: Fix this lmao? - # copts = ["-fsanitize=address", "-g"], - # linkopts = ["-fsanitize=address"], + copts = ["-fsanitize=address", "-g"], + linkopts = ["-fsanitize=address"], ) diff -r 431df06b1a9b -r d39e8860a361 dowa/d_memory.c --- a/dowa/d_memory.c Thu Jan 01 14:05:34 2026 -0800 +++ b/dowa/d_memory.c Thu Jan 01 14:25:17 2026 -0800 @@ -109,14 +109,19 @@ current_capacity = 0; } - if (current_capacity >= minimum_capacity && p_array != NULL) + // Calculate needed capacity: if minimum_capacity is 0, we need room for at least one more element + size_t needed_capacity = minimum_capacity; + if (p_array && needed_capacity == 0) + needed_capacity = p_header->length + 1; + + if (current_capacity >= needed_capacity && p_array != NULL) return p_array; new_capacity = current_capacity * 2; if (new_capacity < 4) new_capacity = 4; - if (new_capacity < minimum_capacity) - new_capacity = minimum_capacity; + if (new_capacity < needed_capacity) + new_capacity = needed_capacity; size_t total_size = sizeof(Dowa_Array_Header) + (element_size * new_capacity); @@ -479,7 +484,8 @@ memcpy(p_key_copy, p_key, key_size); - memcpy(p_new_element, &p_key_copy, sizeof(char*)); + // Store the pointer value (use memcpy to avoid alignment issues) + memcpy(p_new_element, &p_key_copy, sizeof(p_key_copy)); p_header->length++; // Try to insert into hash table - if it fails, rehash and retry @@ -497,7 +503,7 @@ // Restore array state new_index = (uint32)p_header->length; p_new_element = (char*)p_map + (new_index * element_size); - memcpy(p_new_element, &p_key_copy, sizeof(char*)); + memcpy(p_new_element, &p_key_copy, sizeof(p_key_copy)); p_header->length++; } diff -r 431df06b1a9b -r d39e8860a361 dowa/dowa_test.c --- a/dowa/dowa_test.c Thu Jan 01 14:05:34 2026 -0800 +++ b/dowa/dowa_test.c Thu Jan 01 14:25:17 2026 -0800 @@ -212,6 +212,58 @@ Dowa_HashMap_Free(p_large_map); printf(" Medium map freed\n\n"); + // --- Test Key Storage Integrity --- + printf("Testing Key Storage Integrity (Regression Test)...\n"); + Dowa_KV(char*, char*)* p_integrity_map = NULL; + + // Simple test first + Dowa_HashMap_Push(p_integrity_map, "HTTP_Method", "GET"); + Dowa_HashMap_Push(p_integrity_map, "Path", "/index.html"); + + printf(" Testing simple 2-key map...\n"); + void* p_method = Dowa_HashMap_Get_Ptr(p_integrity_map, "HTTP_Method"); + void* p_path = Dowa_HashMap_Get_Ptr(p_integrity_map, "Path"); + + if (p_method && p_path) + { + Dowa_KV(char*, char*)* p_m = (Dowa_KV(char*, char*)*)p_method; + Dowa_KV(char*, char*)* p_p = (Dowa_KV(char*, char*)*)p_path; + printf(" Method: key='%s', value='%s'\n", p_m->key, p_m->value); + printf(" Path: key='%s', value='%s'\n", p_p->key, p_p->value); + printf(" PASS: Simple test passed\n"); + } + else + { + printf(" FAIL: Could not find keys\n"); + } + + Dowa_HashMap_Free(p_integrity_map); + p_integrity_map = NULL; + + // Test with arena allocator + printf(" Testing arena-allocated map...\n"); + Dowa_Arena *p_integrity_arena = Dowa_Arena_Create(4096); + Dowa_HashMap_Push_Arena(p_integrity_map, "HTTP_Method", "POST", p_integrity_arena); + Dowa_HashMap_Push_Arena(p_integrity_map, "Content-Type", "application/json", p_integrity_arena); + + p_method = Dowa_HashMap_Get_Ptr(p_integrity_map, "HTTP_Method"); + void* p_content_type = Dowa_HashMap_Get_Ptr(p_integrity_map, "Content-Type"); + + if (p_method && p_content_type) + { + Dowa_KV(char*, char*)* p_m = (Dowa_KV(char*, char*)*)p_method; + Dowa_KV(char*, char*)* p_ct = (Dowa_KV(char*, char*)*)p_content_type; + printf(" Method: key='%s', value='%s'\n", p_m->key, p_m->value); + printf(" Content-Type: key='%s', value='%s'\n", p_ct->key, p_ct->value); + printf(" PASS: Arena test passed\n"); + } + else + { + printf(" FAIL: Could not find keys\n"); + } + + Dowa_Arena_Free(p_integrity_arena); + printf(" Key integrity test complete\n\n"); printf("=== String Manipulations === \n\n");