88
99// ///////////////////////////////////////////////////////////////////////////
1010// ===========================================================================
11+ static inline size_t cc_string_allocated_size (cc_string_t * s)
12+ {
13+ size_t current = 1 ;
14+
15+
16+ while (current < (s->capacity ))
17+ current <<= 1 ;
18+ return current;
19+ }
20+
1121static void string_append (bool memory_leack)
1222{
1323 test_out
@@ -17,15 +27,17 @@ static void string_append(bool memory_leack)
1727
1828
1929 cc_string_t s;
30+ cc_string_t s0;
31+ cc_string_t s1;
32+
33+
2034 cc_string_create (&s, cc_default_string_heap_memory_allocator ());
2135 cc_string_append (&s, " Hello" );
2236
2337
2438
25- cc_string_t s0;
2639 cc_string_create (&s0, cc_default_string_heap_memory_allocator ());
2740
28- cc_string_t s1;
2941 cc_string_create (&s1, cc_default_string_heap_memory_allocator ());
3042 cc_string_append (&s1, " <Hello" );
3143 cc_string_append (&s1, " World>" );
@@ -35,7 +47,7 @@ static void string_append(bool memory_leack)
3547 cc_string_append (&s1, " <World>" );
3648
3749
38- for (size_t i = 0 ; i < 10 ; i++)
50+ for (size_t i = 0 ; i < 20 ; i++)
3951 {
4052 cc_string_append (&s0, cc_string_c_str (&s1));
4153 test_out
@@ -46,15 +58,45 @@ static void string_append(bool memory_leack)
4658 ;
4759 }
4860
61+
4962 if (memory_leack == false )
5063 {
5164 cc_string_destroy (&s1);
5265 }
66+ else
67+ {
68+ test_out << " Memory Leak Test: Skip cc_string_destroy(&s1)" << test_tendl;
69+ }
5370
5471 test_out << " s0: data=" << cc_string_c_str (&s0) << test_tendl;
5572
5673
5774
75+ if (memory_leack == false )
76+ {
77+ cc_string_destroy (&s0);
78+ }
79+ else
80+ {
81+ size_t alignment = sizeof (void *) * 2 ;
82+ size_t s0_string_memory_size = s0.capacity + 1 ;
83+ size_t s0_string_memory_aligned_size =
84+ s0_string_memory_size / alignment * alignment + ((s0_string_memory_size % alignment) ? alignment : 0 );
85+
86+ size_t s0_memory_leak_size =
87+ sizeof (cc_first_fit_block_head_t ) +
88+ s0_string_memory_aligned_size;
89+ ;
90+
91+ uintptr_t s0_address = (uintptr_t )&s0.data [0 ];
92+
93+ test_out << " Memory Leak Test: Skip cc_string_destroy(&s0):"
94+ << " s0_memory_leak_size=" << s0_memory_leak_size
95+ << " s0.data =" << (void *)s0_address
96+ << test_tendl;
97+ }
98+
99+
58100 if (memory_leack == false )
59101 {
60102 cc_string_destroy (&s);
0 commit comments