boost-ext / te

C++17 Run-time Polymorphism (Type Erasure) library
451 stars 38 forks source link

Bug : segmentation fault #31

Closed pfeatherstone closed 2 years ago

pfeatherstone commented 2 years ago

Expected Behavior

We expect the following to work.

Actual Behavior

We get a segmentation fault. It breaks when using local_storage and using move semantics. The library just moves or swaps the underlying pointers. That won't work. Explicit move constructors MUST be called. So I believe void_ptr should be upgraded to include:

  using ptr_t = void *;
  using del_t = void (*)(ptr_t);
  using copy_t = ptr_t (*)(ptr_t);
  using move_t = ptr_t(*)(ptr_t);

  ptr_t ptr;
  del_t del;
  copy_t copy;
  move_t move;

Steps to Reproduce the Problem

Run the godbolt link.

Specifications

Run on any system and it will break.

pfeatherstone commented 2 years ago

If i run on my local machine i get output:

s1 `���-�` addr : 0x7fff2dc0c350
s2 `world` addr : 0x7fff2dc0c380
pfeatherstone commented 2 years ago

I've had a go at fixing this. I'm not convinced the changes to void_ptr are trivial.

pfeatherstone commented 2 years ago

First bug is use of std::aligned_storage<Size, Alignment> instead of std::aligned_storage_t<Size, Alignment>

pfeatherstone commented 2 years ago

@krzysztof-jusiak any ideas ?

pfeatherstone commented 2 years ago

I think i've fixed the library. But it definitely isn't polished. Here is a godbolt link

krzysztof-jusiak commented 2 years ago

nice @pfeatherstone :clamp: Could you create a PR, please? thanks

pfeatherstone commented 2 years ago

@krzysztof-jusiak Yes no problem

pfeatherstone commented 2 years ago

Solved