@@ -91,3 +91,60 @@ test_aligned_alloc_valid_alignments(void **state)
9191
9292 mem_allocator_destroy (allocator );
9393}
94+
95+ /* Test: Realloc rejects aligned allocations */
96+ static void
97+ test_realloc_rejects_aligned (void * * state )
98+ {
99+ mem_allocator_t allocator ;
100+ char heap_buf [64 * 1024 ];
101+ void * ptr , * new_ptr ;
102+
103+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
104+ assert_non_null (allocator );
105+
106+ /* Allocate aligned */
107+ ptr = mem_allocator_malloc_aligned (allocator , 128 , 64 );
108+ assert_non_null (ptr );
109+ assert_true (is_aligned_allocation (ptr ));
110+
111+ /* Realloc should reject aligned allocation */
112+ new_ptr = mem_allocator_realloc (allocator , ptr , 256 );
113+ assert_null (new_ptr );
114+
115+ /* Original pointer should still be valid - free it */
116+ mem_allocator_free (allocator , ptr );
117+
118+ mem_allocator_destroy (allocator );
119+ }
120+
121+ /* Test: Realloc still works for normal allocations */
122+ static void
123+ test_normal_realloc_works (void * * state )
124+ {
125+ mem_allocator_t allocator ;
126+ char heap_buf [64 * 1024 ];
127+ void * ptr , * new_ptr ;
128+
129+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
130+ assert_non_null (allocator );
131+
132+ /* Allocate normal */
133+ ptr = mem_allocator_malloc (allocator , 128 );
134+ assert_non_null (ptr );
135+
136+ /* Write some data */
137+ memset (ptr , 0xAB , 128 );
138+
139+ /* Realloc should work */
140+ new_ptr = mem_allocator_realloc (allocator , ptr , 256 );
141+ assert_non_null (new_ptr );
142+
143+ /* Data should be preserved */
144+ for (int i = 0 ; i < 128 ; i ++ ) {
145+ assert_int_equal (((unsigned char * )new_ptr )[i ], 0xAB );
146+ }
147+
148+ mem_allocator_free (allocator , new_ptr );
149+ mem_allocator_destroy (allocator );
150+ }
0 commit comments