@cryptotaxi247 / netdata-1 / commits / a04c63be7

fix 32bit calculation on array allocator (#13343)

fix aral on 31bit

Costa Tsaousis committed Jul 8, 2022 at 20:18 UTC a04c63be7fa1bb633265cba4abccd105b4b25c42
2 files changed +7 -7
libnetdata/arrayalloc/arrayalloc.c
+4 -4
@@ -50,14 +50,14 @@ static void arrayalloc_init(ARAL *ar) {
50 ar->internal.element_size = natural_alignment(ar->element_size, sizeof(uintptr_t));
51
52 // then add the size of a pointer to it
53 - ar->internal.element_size = ar->internal.element_size + sizeof(uintptr_t);
53 + ar->internal.element_size += sizeof(uintptr_t);
54
55 // make sure it is at least what we need for an ARAL_FREE slot
56 if (ar->internal.element_size < sizeof(ARAL_FREE))
57 ar->internal.element_size = sizeof(ARAL_FREE);
58
59 // and finally align it to the natural alignment
60 - ar->internal.element_size = natural_alignment(ar->element_size, ARAL_NATURAL_ALIGNMENT);
60 + ar->internal.element_size = natural_alignment(ar->internal.element_size, ARAL_NATURAL_ALIGNMENT);
61
62 // this is where we should write the pointer
63 ar->internal.page_ptr_offset = ar->internal.element_size - sizeof(uintptr_t);
@@ -151,11 +151,11 @@ static inline void link_page_last(ARAL *ar, ARAL_PAGE *page) {
151 }
152
153 static inline ARAL_PAGE *find_page_with_allocation(ARAL *ar, void *ptr) {
154 - size_t seeking = (size_t)ptr;
154 + uintptr_t seeking = (uintptr_t)ptr;
155 ARAL_PAGE *page;
156
157 for(page = ar->internal.first_page; page ; page = page->next) {
158 - if(unlikely(seeking >= (size_t)page->data && seeking < (size_t)page->data + page->size))
158 + if(unlikely(seeking >= (uintptr_t)page->data && seeking < (uintptr_t)page->data + page->size))
159 break;
160 }
161
libnetdata/onewayalloc/onewayalloc.c
+3 -3
@@ -145,11 +145,11 @@ void onewayalloc_freez(ONEWAYALLOC *owa __maybe_unused, const void *ptr __maybe_
145
146 OWA_PAGE *head = (OWA_PAGE *)owa;
147 OWA_PAGE *page;
148 - size_t seeking = (size_t)ptr;
148 + uintptr_t seeking = (uintptr_t)ptr;
149
150 for(page = head; page ;page = page->next) {
151 - size_t start = (size_t)page;
152 - size_t end = start + page->size;
151 + uintptr_t start = (uintptr_t)page;
152 + uintptr_t end = start + page->size;
153
154 if(seeking >= start && seeking <= end) {
155 // found it - it is ours