@@ -345,6 +345,7 @@ void test_buddy_resize_up_within_reserved(void) {
345345 buddy = buddy_init (buddy_buf , data_buf , 768 );
346346 assert (buddy != NULL );
347347 assert (buddy_resize (buddy , 896 ) == buddy );
348+ assert (buddy_resize (buddy , 768 ) == buddy );
348349 free (buddy_buf );
349350}
350351
@@ -356,6 +357,7 @@ void test_buddy_resize_up_at_reserved(void) {
356357 buddy = buddy_init (buddy_buf , data_buf , 768 );
357358 assert (buddy != NULL );
358359 assert (buddy_resize (buddy , 1024 ) == buddy );
360+ assert (buddy_resize (buddy , 768 ) == buddy );
359361 free (buddy_buf );
360362}
361363
@@ -367,6 +369,7 @@ void test_buddy_resize_up_after_reserved(void) {
367369 buddy = buddy_init (buddy_buf , data_buf , 768 );
368370 assert (buddy != NULL );
369371 assert (buddy_resize (buddy , 2048 ) == buddy );
372+ assert (buddy_resize (buddy , 768 ) == buddy );
370373 free (buddy_buf );
371374}
372375
@@ -378,6 +381,7 @@ void test_buddy_resize_down_to_virtual(void) {
378381 buddy = buddy_init (buddy_buf , data_buf , 1024 );
379382 assert (buddy != NULL );
380383 assert (buddy_resize (buddy , 832 ) == buddy );
384+ assert (buddy_resize (buddy , 1024 ) == buddy );
381385 free (buddy_buf );
382386}
383387
@@ -389,6 +393,7 @@ void test_buddy_resize_down_to_virtual_partial(void) {
389393 buddy = buddy_init (buddy_buf , data_buf , 1024 );
390394 assert (buddy != NULL );
391395 assert (buddy_resize (buddy , 832 - 1 ) == buddy );
396+ assert (buddy_resize (buddy , 1024 ) == buddy );
392397 free (buddy_buf );
393398}
394399
@@ -400,6 +405,7 @@ void test_buddy_resize_down_within_reserved(void) {
400405 buddy = buddy_init (buddy_buf , data_buf , 768 );
401406 assert (buddy != NULL );
402407 assert (buddy_resize (buddy , 640 ) == buddy );
408+ assert (buddy_resize (buddy , 768 ) == buddy );
403409 free (buddy_buf );
404410}
405411
@@ -428,6 +434,7 @@ void test_buddy_resize_down_at_reserved(void) {
428434 buddy = buddy_init (buddy_buf , data_buf , 768 );
429435 assert (buddy != NULL );
430436 assert (buddy_resize (buddy , 512 ) == buddy );
437+ assert (buddy_resize (buddy , 768 ) == buddy );
431438 free (buddy_buf );
432439}
433440
@@ -439,6 +446,7 @@ void test_buddy_resize_down_before_reserved(void) {
439446 buddy = buddy_init (buddy_buf , data_buf , 768 );
440447 assert (buddy != NULL );
441448 assert (buddy_resize (buddy , 448 ) == buddy );
449+ assert (buddy_resize (buddy , 768 ) == buddy );
442450 free (buddy_buf );
443451}
444452
@@ -883,11 +891,11 @@ void test_buddy_safe_free_coverage(void) {
883891 start_test ;
884892 buddy = buddy_init (buddy_buf , data_buf + 1024 , 1024 );
885893 assert (buddy != NULL );
886- buddy_safe_free (NULL , NULL , 0 );
887- buddy_safe_free (NULL , data_buf + 1024 , 0 );
888- buddy_safe_free (buddy , NULL , 0 );
889- buddy_safe_free (buddy , data_buf , 0 );
890- buddy_safe_free (buddy , data_buf + 2048 , 0 );
894+ assert ( buddy_safe_free (NULL , NULL , 0 ) == BUDDY_SAFE_FREE_BUDDY_IS_NULL );
895+ assert ( buddy_safe_free (buddy , NULL , 0 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
896+ assert ( buddy_safe_free (buddy , data_buf , 0 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
897+ assert ( buddy_safe_free (buddy , data_buf + 2048 , 0 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
898+ assert ( buddy_safe_free (buddy , data_buf + 1024 , 1024 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
891899 free (buddy_buf );
892900}
893901
@@ -897,7 +905,7 @@ void test_buddy_safe_free_alignment(void) {
897905 struct buddy * buddy ;
898906 start_test ;
899907 buddy = buddy_init (buddy_buf , data_buf , 4096 );
900- buddy_safe_free (buddy , data_buf + 1 , 0 );
908+ assert ( buddy_safe_free (buddy , data_buf + 1 , 0 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
901909 free (buddy_buf );
902910}
903911
@@ -915,11 +923,11 @@ void test_buddy_safe_free_invalid_free_01(void) {
915923 r = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN );
916924 assert (r != NULL );
917925 assert (l != r );
918- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
926+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
919927 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
920928 // double-free on a right node
921929 // that will propagate to a partially-allocated parent
922- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
930+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
923931 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
924932 free (buddy_buf );
925933 free (buddy_buf_control );
@@ -939,12 +947,12 @@ void test_buddy_safe_free_invalid_free_02(void) {
939947 r = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN );
940948 assert (r != NULL );
941949 assert (l != r );
942- buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN );
943- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
950+ assert ( buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
951+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
944952 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
945953 // double-free on a right node
946954 // that will propagate to a unallocated parent
947- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
955+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
948956 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
949957 free (buddy_buf );
950958 free (buddy_buf_control );
@@ -964,14 +972,14 @@ void test_buddy_safe_free_invalid_free_03(void) {
964972 r = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN );
965973 assert (r != NULL );
966974 assert (l != r );
967- buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN );
968- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
975+ assert ( buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
976+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
969977 m = buddy_malloc (buddy , size ); // full allocation
970978 assert (m == l ); // at the start of the arena
971979 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
972980 // double-free on a right node
973981 // that will propagate to a fully-allocated parent
974- buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN );
982+ assert ( buddy_safe_free (buddy , r , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
975983 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
976984 free (buddy_buf );
977985 free (buddy_buf_control );
@@ -991,12 +999,11 @@ void test_buddy_safe_free_invalid_free_04(void) {
991999 r = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN );
9921000 assert (r != NULL );
9931001 assert (l != r );
994- buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN );
1002+ assert ( buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SUCCESS );
9951003 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
9961004 // double-free on a left node
9971005 // that will propagate to a partially-allocated parent
998- buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN );
999- /* the use check in buddy_tree_release handles this case */
1006+ assert (buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN * 2 ) == BUDDY_SAFE_FREE_INVALID_ADDRESS );
10001007 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
10011008 free (buddy_buf );
10021009 free (buddy_buf_control );
@@ -1014,7 +1021,7 @@ void test_buddy_safe_free_invalid_free_05(void) {
10141021 l = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN );
10151022 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
10161023 // safe free with double size
1017- buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN * 2 );
1024+ assert ( buddy_safe_free (buddy , l , BUDDY_ALLOC_ALIGN * 2 ) == BUDDY_SAFE_FREE_SIZE_MISMATCH );
10181025 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
10191026 free (buddy_buf );
10201027 free (buddy_buf_control );
@@ -1032,7 +1039,7 @@ void test_buddy_safe_free_invalid_free_06(void) {
10321039 m = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN * 2 );
10331040 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
10341041 // safe free with half size
1035- buddy_safe_free (buddy , m , BUDDY_ALLOC_ALIGN );
1042+ assert ( buddy_safe_free (buddy , m , BUDDY_ALLOC_ALIGN ) == BUDDY_SAFE_FREE_SIZE_MISMATCH );
10361043 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
10371044 free (buddy_buf );
10381045 free (buddy_buf_control );
@@ -1050,7 +1057,7 @@ void test_buddy_safe_free_invalid_free_07(void) {
10501057 m = buddy_malloc (buddy , BUDDY_ALLOC_ALIGN * 2 );
10511058 memcpy (buddy_buf_control , buddy_buf , buddy_sizeof (size ));
10521059 // safe free with zero size
1053- buddy_safe_free (buddy , m , 0 );
1060+ assert ( buddy_safe_free (buddy , m , 0 ) == BUDDY_SAFE_FREE_SIZE_MISMATCH );
10541061 assert (memcmp (buddy_buf_control , buddy_buf , buddy_sizeof (size )) == 0 );
10551062 free (buddy_buf );
10561063 free (buddy_buf_control );
0 commit comments