Skip to content

Commit

Permalink
Merge pull request gnuradio#523 from AlexandreRouma/main
Browse files Browse the repository at this point in the history
Fix allocated size not a multiple of alignment
  • Loading branch information
jdemel authored Oct 2, 2021
2 parents 89029fa + a0837c0 commit 8867620
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/volk_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@

void* volk_malloc(size_t size, size_t alignment)
{
if ((size == 0) || (alignment == 0)) {
fprintf(stderr, "VOLK: Error allocating memory: either size or alignment is 0");
return NULL;
}
// Tweak size to satisfy ASAN (the GCC address sanitizer).
// Calling 'volk_malloc' might therefor result in the allocation of more memory than
// requested for correct alignment. Any allocation size change here will in general not
// impact the end result since initial size alignment is required either way.
if (size % alignment) {
size += alignment - (size % alignment);
}
#if HAVE_POSIX_MEMALIGN
// quoting posix_memalign() man page:
// "alignment must be a power of two and a multiple of sizeof(void *)"
Expand Down

0 comments on commit 8867620

Please sign in to comment.