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

Parametrized test crashes when calling virtual function #532

Open
Mirkopoj opened this issue Apr 29, 2024 · 0 comments
Open

Parametrized test crashes when calling virtual function #532

Mirkopoj opened this issue Apr 29, 2024 · 0 comments

Comments

@Mirkopoj
Copy link

Mirkopoj commented Apr 29, 2024

class Cont : public Stack {
public:
  StackableObject **stack;
  size_t count;
  Cont(int initial_capacity)
      : count(0), stack(new StackableObject *[initial_capacity]) {}
  ~Cont() { delete[] stack; }

  size_t read_count() const { return this->count; }

  virtual size_t get_count() const override { return this->count; }
  virtual bool push(StackableObject *const new_stackable) override {
    this->stack[this->count] = new_stackable;
    this->count++;
    return true;
  }
  virtual StackableObject *pop() override {
    this->count--;
    return this->stack[this->count];
  }
};

criterion::parameters<std::unique_ptr<Cont>> parameters;
ParameterizedTestParameters(params, cleanup) {
  parameters.push_back(std::make_unique<Cont>(2));
  std::cout << "parameters: " << &parameters << "\n";
  std::cout << "parameter 0: " << &(*parameters[0]) << "\n";
  std::cout << "parameter 0 get_count: " << (*parameters[0]).get_count()
            << "\n";
  return parameters;
}

ParameterizedTest(std::unique_ptr<Cont> &dyn_cont, params, cleanup) {
  std::cout << "dyn_cont: " << &dyn_cont << "\n";
  std::cout << "*dyn_cont: " << &(*dyn_cont) << "\n";
  int count = (*dyn_cont).count;
  printf("Parameters: (%d)\n", count);
  count = (*dyn_cont).read_count();
  printf("Parameters: (%d)\n", count);
  count = (*dyn_cont).get_count();
  printf("Parameters: (%d)\n", count);
}
new
new[]
parameters: 0x582ca41bf310
parameter 0: 0x4e91ec000038
parameter 0 get_count: 0
dyn_cont: 0x7aac42037280
*dyn_cont: 0x4e91ec000038
Parameters: (0)
Parameters: (0)
[----] src/tests/dynamic_mem.cpp:86: Unexpected signal caught below this line!
[FAIL] params::cleanup: CRASH!
[====] Synthesis: Tested: 1 | Passing: 0 | Failing: 1 | Crashing: 1 
delete[]
delete

I overwrote all allocations to use criterion's those news and deletes printed in the output show they get called, when accesing the count attribute, or reading it via a local method (read_count()) everything works, but when I call the get_count() virtual method I get a crash.

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