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] new instance with invalid parameters problem #58

Closed
SkibidiProduction opened this issue Jul 9, 2024 · 3 comments · Fixed by #59 or #60
Closed

[BUG] new instance with invalid parameters problem #58

SkibidiProduction opened this issue Jul 9, 2024 · 3 comments · Fixed by #59 or #60
Assignees
Labels
bug Something isn't working segfault Segmentation faults, double frees and core dumps errors
Milestone

Comments

@SkibidiProduction
Copy link
Contributor

When running the following code:

new NDArray();

I expect to receive:

Fatal error: Uncaught ArgumentCountError: NDArray::__construct() expects exactly 1 argument, 0 given

Instead I get a segmentation fault:

Segmentation fault (core dumped)

The same problem occurs if I try to pass an empty array or invalid value:

new NDArray([]);
//Segmentation fault (core dumped)

new NDArray('string');
//Segmentation fault (core dumped)

If we talk about the problem of passing an empty array, then in #54 and #56 I processed this case and threw an exception. However, now I think that perhaps this is not quite the right approach and we should give the user the opportunity to create instances of the class from an empty array.

@SkibidiProduction SkibidiProduction added the bug Something isn't working label Jul 9, 2024
@SkibidiProduction SkibidiProduction changed the title [BUG] new instance with empty __construct problem [BUG] new instance with invalid parameters problem Jul 9, 2024
@henrique-borba henrique-borba added this to the 0.5.2 milestone Jul 9, 2024
@henrique-borba henrique-borba added the segfault Segmentation faults, double frees and core dumps errors label Jul 9, 2024
@henrique-borba henrique-borba linked a pull request Jul 9, 2024 that will close this issue
@henrique-borba
Copy link
Member

henrique-borba commented Jul 9, 2024

After testing with valgrind, I identified that the error occurred when calling the destructor. It appears that PHP calls the destructor before dealing with __construct method exceptions. The destructor was trying to free an NDArray that did not exist.

Fixed by #59

@henrique-borba henrique-borba moved this to In Progress in NumPower Extension Jul 9, 2024
@henrique-borba
Copy link
Member

The constructor is already supporting an empty array now, but I found that the __toString method and print_r are not able to handle empty arrays. I will correct this in another MR.

@henrique-borba
Copy link
Member

Empty array initialization fixed in #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working segfault Segmentation faults, double frees and core dumps errors
Projects
2 participants