Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in pipeline_t::set_cache? #79

Open
BinDong314 opened this issue Feb 15, 2023 · 0 comments
Open

Bug in pipeline_t::set_cache? #79

BinDong314 opened this issue Feb 15, 2023 · 0 comments

Comments

@BinDong314
Copy link

BinDong314 commented Feb 15, 2023

Hi @steven-varga and H5CPP:
By using h5cpp recently, I found a potential bug (not 100% sure) in the code for the function pipeline_t::set_cache

inline void h5::impl::pipeline_t<Derived>::set_cache( const h5::dcpl_t& dcpl, size_t element_size ) {

When I ran my own app, it reports below error:
CTOR: couldn't allocate memory for caching chunks, invalid/check size?
libc++abi: terminating with uncaught exception of type h5::error::io::packet_table::misc:
H5Dappend.hpp line# 167 : CTOR: unable to create handle from dataset...

Below are minimum code to demo the error, when the block_size (1110) is not multiple of H5CPP_MEM_ALIGNMENT (64).
It will report the error. Any idea to bypass this error or fix it?

Replacing "aligned_alloc" with normal "alloc" could be an option when the block_size % H5CPP_MEM_ALIGNMENT != 0

Bests,
Bin

#define H5CPP_MEM_ALIGNMENT 64

#include <stdio.h>
#include <stdlib.h>
#include
#include
#include
#include
#include
#include
#include

int main()
{
size_t block_size = 1110;
char *chunk0, *chunk1;

std::unique_ptr<char> ptr0, ptr1; // will call std::free on dtor

ptr0 = std::move(std::unique_ptr<char>{(char *)aligned_alloc(H5CPP_MEM_ALIGNMENT, block_size)});
ptr1 = std::move(std::unique_ptr<char>{(char *)aligned_alloc(H5CPP_MEM_ALIGNMENT, block_size)});
// get an alias to smart ptr
if ((chunk0 = ptr0.get()) == NULL || (chunk1 = ptr1.get()) == NULL)
{
    std::cout << "CTOR: couldn't allocate memory for caching chunks, invalid/check size? \n";
    // throw h5::error::io::dataset::open(H5CPP_ERROR_MSG("CTOR: couldn't allocate memory for caching chunks, invalid/check size?"));
}

}

The aligned_alloc seems to require "the size parameter must be an integral multiple of alignment."
https://en.cppreference.com/w/c/memory/aligned_alloc

void *aligned_alloc( size_t alignment, size_t size );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant