Skip to content

Bug in pipeline_t::set_cache? #79

@BinDong314

Description

@BinDong314

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 );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions