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

Fix sizeof usage for Variant pointers in alloca #84925

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

alesliehughes
Copy link
Contributor

A few Coverity issue pickup with the use of sizeof, and in these cases are the same size.

@alesliehughes alesliehughes requested review from a team as code owners November 15, 2023 03:47
@AThousandShips
Copy link
Member

I don't think them technically being the same matters here, having the actual type is important

@alesliehughes
Copy link
Contributor Author

No sure how it matters with the sizeof usage as there is a clear cast as to the type they want it to be.

@AThousandShips
Copy link
Member

Why does it not matter? It makes it clear what we want in case we change anything and need to update it, what's the problem with having the actual type for clarity?

@alesliehughes
Copy link
Contributor Author

Sizeof should have an actual type, not a array of pointer type. Regardless its still clear that the allocation is for a list of pointers.
The way it reads if your not careful is a double list of pointers.

@akien-mga akien-mga requested a review from KoBeWi November 15, 2023 09:45
@AThousandShips
Copy link
Member

My bad you're right it's taking the pointer type, this is correct, misread your description

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, confusion over the type to store

Edit: confirmed the new code matches what is done elsewhere

@@ -133,7 +133,7 @@ void CallableCustomBind::get_bound_arguments(Vector<Variant> &r_arguments, int &
}

void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount));
const Variant **args = (const Variant **)alloca(sizeof(const Variant *) * (binds.size() + p_argcount));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Variant **args = (const Variant **)alloca(sizeof(const Variant *) * (binds.size() + p_argcount));
const Variant **args = (const Variant **)alloca(sizeof(Variant *) * (binds.size() + p_argcount));

Minor suggestion to match the other instances, such as Object::callv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want it part of this request or other one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this, were already fixing it 🙂

@akien-mga
Copy link
Member

I would suggest squashing the commits, as they both fix the same issue in separate parts of the code.

@akien-mga akien-mga changed the title Fix sizeof usage Fix sizeof usage for Variant pointers in alloca Nov 15, 2023
@akien-mga akien-mga changed the title Fix sizeof usage for Variant pointers in alloca Fix sizeof usage for Variant pointers in alloca Nov 15, 2023
Coverity report this as a non portable usage of sizeof
@akien-mga akien-mga modified the milestones: 4.x, 4.3 Nov 15, 2023
@akien-mga akien-mga modified the milestones: 4.3, 4.2 Nov 16, 2023
@akien-mga akien-mga merged commit 25b0b46 into godotengine:master Nov 16, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants